users@jersey.java.net

Re: [Jersey] RE: JAXB/JSON Array reading problem (Array writing is OK)

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 19 Aug 2008 00:45:54 +0200

Hi Tyson,

please see inline...

On Mon, Aug 18, 2008 at 10:30:23AM -0700, Tyson Norris wrote:
> Thanks Paul.
>
>
>
> You are right - my case is NOT returning a Collection, but returning a
> JAXB bean that has a Collection property.
>
>
>
> More testing indicated that:
>
> Collection/List typed property:
>
> - JSON: Collection/List property is returned via GET; property
> is NOT assigned when submitting similar valid format via POST (i.e.
> POSTing the same data that was returned from GET does not work)
>
> - XML: Collection/List property is returned properly via GET;
> property is NOT assigned when submitting similar valid format via POST
> (need to verify this again, but 99% sure this was the case)

Then the behaviour is same whatever mime-type is used, right?
It would indicate no bug in JSON.
Maybe a bug in jaxb, then, maybe there is missing something.
Sending out your JAXB beans would be helpful.
>
> Array typed property:
>
> - JSON: Array property is returned via GET and assigned via
> POST
>
> - XML: need to test this

I would think XML should work in this case, as JSON defers to JAXB/XML.
You use the same JAXB beans, right?
>
>
>
> I will work out a simple test and pass it on the list ASAP.

Great, feel free to directly report a bug at [1] and attach your test case there.

~Jakub

[1]https://jersey.dev.java.net/issues/

>
>
>
> Thanks
>
> Tyson
>
>
>
>
>
> ________________________________
>
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Monday, August 18, 2008 12:24 AM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] RE: JAXB/JSON Array reading problem (Array writing
> is OK)
>
>
>
> Hi Tyson,
>
>
>
> That bug is related to a resource method returning a collection. If i
> understand correctly, in your case, it is something to do with a
> collection as a JAXB property i.e. your top-level JAXB beans are getting
> instantiated but some part of it is not.
>
>
>
> Perhaps you can verify the following:
>
>
>
> 1) Returning an instance of MyObj as XML or JSON. It may be that the
> JSON that is generated is not what you expect. In general JAXB ignores
> stuff it does not understand so it could be ignoring the JSON
> information associated with "collectionValues" because it does not have
> the required XML infoset structure i.e. do
>
>
>
> @GET
>
> @Produces(<xml and json>)
>
> public MyObj get() {
>
> MyObj o = ....
>
> return o;
>
> }
>
>
>
> 2) Check that it works with XML.
>
>
>
> Also can you send the JAXB beans?
>
>
>
> Thanks,
>
> Paul.
>
>
>
> On Aug 16, 2008, at 12:16 AM, Tyson Norris wrote:
>
>
>
>
>
> Whoops...
>
> Just noticed this:
>
> https://jersey.dev.java.net/issues/show_bug.cgi?id=18
>
>
>
> I will try out creating a Collection wrapper.
>
>
>
> Sorry for the noise...
>
> Tyson
>
>
>
> ________________________________
>
> From: Tyson Norris
> Sent: Friday, August 15, 2008 2:49 PM
> To: 'users_at_jersey.dev.java.net'
> Subject: RE: JAXB/JSON Array reading problem (Array writing is OK)
>
>
>
> Some additional info I forgot to mention:
>
> - version: I'm using 0.8ea version of Jersey
>
> - my collection elements are getting created properly, and the
> collection is read from the converter (by JAXB unmarshaller) but the
> collection is never assigned to the converter property.
>
> I will try a similar test with XML data and see what happens...
>
> Tyson
>
>
>
> ________________________________
>
> From: Tyson Norris
> Sent: Friday, August 15, 2008 2:31 PM
> To: 'users_at_jersey.dev.java.net'
> Subject: JAXB/JSON Array reading problem (Array writing is OK)
>
>
>
> 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
>
>
>
>
>

-- 
http://blogs.sun.com/japod