users@jersey.java.net

[Jersey] Re: Jersey Client unmarshalls empty arrays strangely...

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Mon, 21 Mar 2011 14:09:20 +0100

Hi Dan,

you may want to use the POJO mapping feature on the client:

ClientConfig cc = new DefaultClientConfig();
cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client c = Client.create(cc);

then the empty lists should get properly deserialized by the Jackson
JSON provider.

~Jakub

On 02/28/2011 06:40 PM, dslack_at_langui.com wrote:
> Hello,
>
> I searched through the mailing list and didn't see this question posed.
>
> I'm having an issue using the Jersey Client to properly unmarshall a
> List of objects. First, I'm using Glassfish v3.1, and my web service
> is returning JSON.
>
> Basically, when I return a List of objects that are empty, it gets
> marshalled into an empty JSON Array (as expected), however, when I use
> the Jersey Client to unmarshall, it creates a List with one entry, with
> all null values. I'm not really sure why this is occuring, and I've
> resorted to a horrible hack whereby I check if the 0th entry has a null
> ID field (which should never be null).
>
> I'm registering my own JAXBContextResolver for the Object type, and I'm
> using natural() building.
>
> I've seen this question posed once before (on stackoverflow), but there
> weren't any responses. Can anybody help out, or explain to me whats
> going on?
>
> Thanks,
>
> Dan Slack
>