I developed a restful web service via Jersey in Java (JAX-RS) : http://www.vogella.com/articles/REST/article.html
Then I used the Hibernate Technology to map the dat
It seems to me like you are relying on something to automagically map your Java objects to JSON - probably Jackson. I do not personally prefer this method. Instead, I use Jettison and create my own mapping from Java to a Jettison JSONObject object. Then I use the JSONObject (or JSONArray) as the entity. My return statement would be something like this:
return Response.ok().entity(myObjectAsJSON).build();
In the case of returning a list of things, use a JSONArray instead of a JSONObject.
You'll want a helper method to map the Java object to JSON.
public JSONArray deliverableListToJSON(List<Deliverable> deliverables)
throws JSONException {
JSONArray result = new JSONArray();
for(Deliverable deliverable : deliverables) {
JSONObject deliverableJSON = new JSONObject();
deliverableJSON.put("importantValue", deliverable.getImportantValue());
result.put(deliverableJSON);
}
return result;
}
This approach gives you more flexibility and doesn't force you to have public getters and setters for all your fields.