users@jersey.java.net

[Jersey] Re: JSON Processing Using the New Client API

From: Reza Rahman <Reza.Rahman_at_oracle.com>
Date: Thu, 28 Feb 2013 23:36:13 -0500

I got it to work properly. It turns out I was using Jersey 1 by accident...

On 2/28/2013 7:57 PM, Reza Rahman wrote:
> I have a new problem now. My return type is java.util.List and it
> seems like MOXy does not handle that by default. Is that correct? What
> do I need to do?
>
> On 2/27/2013 10:09 AM, Marek Potociar wrote:
>> Hi Reza,
>>
>> please have a look at the existing JSON example (I suggest to use
>> JSON support provided by MOXy if running on GF 4.0, as MOXy should be
>> by default included in GF 4.0):
>> https://github.com/jersey/jersey/blob/master/examples/json-moxy/pom.xml
>>
>> In summary, you need to specify MOXy dependencies (see example pom).
>>
>>
>> On Feb 26, 2013, at 2:42 AM, reza.rahman_at_oracle.com
>> <mailto:reza.rahman_at_oracle.com> wrote:
>>
>>> I am having a bi of trouble with the new API. Here is my server-side
>>> code:
>>>
>>> @GET
>>> @Path("/shortest-path")
>>> @Produces(MediaType.APPLICATION_JSON)
>>> public List<TransitPath> findShortestPath(
>>> @QueryParam("origin")
>>> final String originUnLocode,
>>> @QueryParam("destination")
>>> final String destinationUnLocode,
>>> @QueryParam("deadline")
>>> final String deadline) {
>>>
>>> I've also setup JSON parsing in web.xml:
>>>
>>> <init-param>
>>> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
>>> <param-value>true</param-value>
>>> </init-param>
>>
>> You can remove the above - this parameter only works in Jersey 1.x.
>> Instead, make sure that you register
>> the org.glassfish.jersey.moxy.json.MoxyJsonFeature both in your
>> client and server.
>>
>>>
>>> What is would be the correct corresponding code on the client? What
>>> providers/configuration do I need? Here's what I have (which clearly
>>> could not work):
>>>
>>> final List<TransitPath> transitPaths = graphTraversalResource
>>> .queryParam("origin", origin)
>>> .queryParam("destination", destination)
>>> .request(MediaType.APPLICATION_JSON)
>>> .get(new GenericType<List<TransitPath>>() {});
>>>
>>> Is the list type correct?
>>
>> As noted above, you need to register a feature that provides JSON
>> binding support.
>>
>>>
>>> Thanks in advance.
>>
>> Marek
>>
>