users@jersey.java.net

Re: [Jersey] jersey with jackson

From: Jakub Podlesak <jakub.podlesak_at_ORACLE.COM>
Date: Tue, 26 Oct 2010 11:01:40 +0200

Hi Matthew,

For maven users, it is sufficient to add jersey-json module dependency
and set

com.sun.jersey.api.json.POJOMappingFeature

resource config feature (see [1]) to get the desired behaviour.
Jersey currently depends on Jackson version 1.5.5.

Instructions for non-maven users can be found at [2].

HTH,

~Jakub

[1]https://jersey.dev.java.net/nonav/documentation/latest/json.html#d0e1960
[2]https://jersey.dev.java.net/nonav/documentation/1.4/user-guide.html#chapter_deps
[3]http://download.java.net/maven/2/com/sun/jersey/jersey-archive/1.5-ea03/jersey-archive-1.5-ea03.zip

On 10/25/2010 10:35 PM, Matthew M. Boedicker wrote:
> I am trying to use Jackson to change the way Jersey generates JSON.
> The features I want are:
>
> - single element lists become JSON lists with one element
> - empty lists become empty JSON lists
> - JSON numbers and booleans are used (not everything becomes a JSON String)
> - fields with null values are left out of JSON objects
>
> I am using Jersey 1.4. The way I have gotten these to work are to put
> jackson-core-asl-1.6.1.jar, jackson-jaxrs-asl-1.6.1.jar,
> jackson-mapper-asl-1.6.1.jar, and jackson-xc-1.6.1.jar in my
> classpath. Jersey sees the providers and uses them with no additional
> configuration. To get Jackson to skip null elements I added
> "@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)" to all the
> beans.
>
> I know that Jersey already uses some parts of Jackson. Any way to get
> the same behavior without adding the Jackson jars?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>