Reputation:
Jersey is not showing a list in the JSON output when I retrieve the object using Hibernate. The list within the object is defined like this:
@OneToMany(cascade=CascadeType.ALL)
@OrderColumn
private List<Project> projects = new ArrayList<Project>();
When I retrieve the object (which also contains the projects
list), I get the normal fields (ints and Strings and such), but not this list. When I use the debugger, I can see that the list is indeed there, but Jersey doesn't output it in JSON.
Upvotes: 0
Views: 287
Reputation: 5313
It looks like you need to configure a JSON Serializer such as Jackson. The answers to this question have some guidance on how to do that.
Once you have Jackson with JAXB support configured, you will need to add appropriate JAXB annotations to the Project class (either XML based one or JSON based ones, the serializer can be configured to support either or both). So, for example adding this to Project
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "project"))
public class Project {
Should be enough to serialize Project and it's fields to JSON.
Upvotes: 1