users@jersey.java.net

RE: Differences in json and xml responses

From: <james.lorenzen_at_accenture.com>
Date: Fri, 17 Sep 2010 17:42:56 -0400

After spending the day trying to get this to work, I'm finally giving up.
I first had troubles getting jersey to recognize my Provider and it didn't work until I used the web.xml init-param, com.sun.jersey.config.property.packages, to register the package that contained our rest service and the provider. Only then did jersey recognize my Provider.

Once I got jersey to recognize my Provider I experimented with JSONConfiguration. I first tried

new JSONJAXBContext(JSONConfiguration.natural().build(), types);

And that worked, but it unfortunately produced an unnamed array in JSON. I then added the rootWrapping(false)

new JSONJAXBContext(JSONConfiguration.natural().rootUnwrapping(false).build(), types);

That worked for XML, but produced a runtime exception for JSON

Sep 17, 2010 2:43:43 PM com.sun.jersey.json.impl.writer.Stax2JacksonWriter writeStartElement
SEVERE: null
org.codehaus.jackson.JsonGenerationException: Can not write a field name, expecting a value

This appears to be an outstanding issue with Jersey: http://jersey.576304.n2.nabble.com/Root-Unwrapping-configuration-for-JSON-representation-in-Jersey-1-1-5-td4613395.html#a5544087

I am using jersey 1.2 and see the issue. So I've spent a day on this and am giving up. Personally I think it's a bug in jersey.

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.