users@jersey.java.net

Re: [Jersey] Unmarshaling JAXB object from JSON

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Wed, 01 Apr 2009 09:59:52 -0400

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.
>>
>

I just realized that the formParams are returned in a MultiValuedMap
where the key PostalAddress has a List<String> value which looks like
below when using MultiValuedMap.toString()

PostalAddress=[{streetNumber:"65",street:"Marla
Ln.",stateOrProvince:"MA",postalCode:"01867",country:"USA",city:"Reading"},
{streetNumber:"1",street:"Main
St.",stateOrProvince:"MA",postalCode:"01867",country:"USA",city:"Reading"}]

So I have a List<String> that I need to convert to
List<PostalAddressType> where PostalAddressType is the JAXB generated
bean class.

Does this mean that I need to convert each String in List<String> to
PostalAddressType or can I convert List<String> to convert to
List<PostalAddressType> directly?

I would not be asking such detailed questions except that I am finding
the Provoiders.getMessageBodyReader params type and genericType not
obvious. Perhaps its my lack of clarity on java generics.

Thanks for getting me over this hopefully last hurdle on this thread.

-- 
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com