I'm using Jersey v1.19 as REST framework.
Below is an Xml-Annotated class for a Response.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Data {
private boolean hasErrors; // always appears because primitive
private List<String> remainingJobs;
// getter and setter
}
The problem here is that when remainingJobs
is null
or empty, then it is not included in the JSON response! Example of the response: {"hasErrors": false}
I would like to make it appear in the JSON response that's all. Example of the response I would like to see: {"hasErrors": false, "remainingJobs": null}
or "null"
However, I found out that if I annotate this data member as
@XmlElementWrapper(name = "remainingJobs")
@XmlElement(name = "remainingJob")
private List<String> remainingJobs;
Then it shows the null
. However, the response will be verbose and not pretty when there are actual data. Example:
{"remainingJobs": {"remainingJob": ["J22", "K01"]}, "hasErrors": false}
What I would like:
{"remainingJobs": ["J22", "K01"], "hasErrors": false}
Another issue is that when remainingJobs
is empty (NOT null
) then it is showing as null
!!