Code example for Gson

Methods: toJson

0
        if (subtree) {
            gson = GsonUtil.getSubtreeGson();
        } else { 
            gson = GsonUtil.getIdOnlyGson();
        } 
		return gson.toJson(this);
	} 
     
    public static Item fromJSON(String json) {
 
		Item node;
		Gson gson = GsonUtil.getSubtreeGson();
		 
		node = gson.fromJson(json, Item.class);
		if (node.getId() == null) {
			node.setId(IdGenerator.generate());
		} 
		return node;
	} 
} 
Connect your IDE to all the code out there  Get Codota for Java