users@jersey.java.net

[Jersey] Re: Deserializing JSON using jersey-client

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Mon, 21 Mar 2011 11:51:53 +0100

Hi Gili,

Could you please double-check, you have the jersey-json
added as a dependency and you have set
the JSONConfiguration.FEATURE_POJO_MAPPING on the client?
The version parameter should not do any harm.

~Jakub

On 03/21/2011 04:50 AM, Gili wrote:
> Gili wrote:
>> Hi,
>>
>> I'm running into problems deserializing a JSON response using
>> jersey-client. The resource defines the following method:
>>
>> @GET
>> @Produces(MediaType.APPLICATION_JSON + "; version=1.0")
>> public List getClinics()
>>
>> The client runs the following code:
>>
>> List result = resource().accept(MediaType.APPLICATION_JSON + ";
>> version=1.0").get(new GenericType&lt;List&lt;URI&gt;>()
>> {
>> });
>>
>> And Jersey throws the following exception:
>>
>> SEVERE: A message body reader for Java class
>> java.util.List, and Java type java.util.List, and MIME media type
>> application/octet-stream was not found
>>
>> I understand that Jersey is translating List to application/octet-stream
>> in spite of the fact that I specified accept() with a different mime type.
>> Jackson is serializing List to JSON on the server-side for me. How do I
>> get it to deserialize the JSON back into List?
>>
>> Thank you,
>> Gili
>>
> Upon further investigation, this was caused by this bug:
> http://java.net/jira/browse/JERSEY-687
>
> Grizzly was returning requests without a "Content-Type" header so
> jersey-client defaulted the type to "application/octet-stream". Now I am
> getting:
>
> SEVERE: A message body reader for Java class java.util.List, and Java type
> java.util.List, and MIME media type application/json;version=1.0 was not
> found
>
> Any idea why Jackson is understands that "application/json;version=1.0" is
> JSON when serializing on the server-end but doesn't recognize it on the
> client-end?
>
> Thanks,
> Gili
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Deserializing-JSON-using-jersey-client-tp6191049p6191129.html
> Sent from the Jersey mailing list archive at Nabble.com.
>