users@jersey.java.net

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

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 27 Feb 2013 16:09:03 +0100

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