users@jersey.java.net

Re: [Jersey] Unmarshaling JAXB object from JSON

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 01 Apr 2009 08:21:56 -0400

On Apr 1, 2009, at 8:06 AM, Paul Sandoz wrote:

>
> On Apr 1, 2009, at 1:57 PM, Farrukh Najmi wrote:
>> Hi Paul,
>>
>> If the jsonString represents List<PostalAddressType> where
>> PostalAddressType is my JAXB generated bean then what should c be
>> and how can I create an instance. Sorry for asking such a basic
>> question. Also I note that the second arg to getMessageBodyReader
>> is of a different type. I can get that with following code (thanks
>> Marc):
>>
>> GenericEntity<List<PostalAddressType>> entityPostalAddresses =
>> new
>> GenericEntity<List<PostalAddressType>>(listPostalAddresses) {};
>> Type genericTypePostalAddresses = entityPostalAddresses.getType();
>>
>> So my call looks like:
>>
>> providers.getMessageBodyReader(??, genericTypePostalAddresses,
>> (java.lang.annotation.Annotation[])null, "application/json");
>>
>> and I am unsure how to get the first param in the call.
>>
>
> ?? = entityPostalAddresses.getRawType();
>
> or
>
> List.class
>
I think you want the latter, the former would yield something like
ArrayList.class (or some other impl of the List interface).

> Do not pass null for the annotation array use an empty array:
>
> new Annotation[0]
>
We need to fix this in the JAX-RS javadoc, its not clear whether null
is allowed or not.

Marc.