views:

86

answers:

1

We have a Java List of objects which is marshalled via JSON which is created by Jersey.

The List is called "rows". When there is data we have:

{"records":"1","page":"1","total":"1","rows":[{"id":"692334","cell":["ECS","D","201009","","0","ABCD","11","11","","201009"]}]}

When there is no data we have:

{"page":0,"records":0,"total":0}

How can we make Jersey include the rows field even if the List has a size of 0? What we want is:

{"page":0,"records":0,"total":0,"rows":[]}

Note that we are already using a JAXB ContextResolver to ensure the JSON is correct for a single row. Not sure if we can configure this resolver to solve our problem.

??

+1  A: 

Use Jackson JAX-RS provider instead of alternatives (badgerfish/jettison), which does not do XML-to-JSON conversion. Missing array is most likely due to this conversion. There are multiple ways to configure this (jersey mailing list should have a few), and latest versions may expose it directly via Jersey API.

StaxMan