users@jersey.java.net

JAXB/JSON Array reading problem (Array writing is OK)

From: Tyson Norris <tyson.norris_at_marketlive.com>
Date: Fri, 15 Aug 2008 14:30:33 -0700

Hi -

I am trying to send JSON data into a jersey service using HTTP POST.

 

This works, in general, for me, except one JAXB property is type
Collection, and JAXB does not seem to unmarshall the collection; the
collection value (on the JAXB converter) is always null, and the setter
is never called.

 

For example, I am sending something like:

 

{"myObj":{"prop1" : "value1", "prop2" : "value2", "collectionValues" :
[{"itemProp1" : itemvalue1", "itemProp2":"itemValue2"}]}}

 

My JAXB converter is created properly, and non-collection property
values are assigned (i.e. I see that getProp1() returns "value1", etc),
but: setCollectionValues() is never invoked, and therefore my collection
values are not available in the JAXB object.

 

When I use the same JAXB Object to return data in JSON format, the
collectionValues are properly marshaled to the same JSON format listed
here.

 

I have tried changing the type of collection in the
getCollectionValues/setCollectionValues methods from
java.util.Collection<ItemPropConverter> to
java.util.List<ItemPropConverter>, but I get the same results
(collection is never set when sending data in, data is properly
translated to JSON when sending data out).

 

Any ideas what might cause this?

 

Thanks!

Tyson