users@jersey.java.net

Re: [Jersey] RE: Differences in json and xml responses

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 05 Oct 2010 13:28:04 +0200

Please see in line...

On 09/17/2010 11:42 PM, james.lorenzen_at_accenture.com wrote:
> 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.
>

The bug in Jersey [1], has just been fixed.
You should be able to get this work with the latest Jersey snapshot.

HTH,

~Jakub


[1]https://jersey.dev.java.net/issues/show_bug.cgi?id=478

> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>