Chapter 19. JSON Support via Jackson

Apart from the Jettison JAXB adapter for JSON, RESTEasy also supports integration with the Jackson project. Many users find Jackson's output format more intuitive than the format provided by either BadgerFish or Jettison.
Jackson is available from http://jackson.codehaus.org. It lets you easily marshal Java objects to and from JSON. Jackson has a JavaBean-based model and JAXB-like APIs. RESTEasy integrates with the JavaBean model as described in the Jackson Tutorial.
To include Jackson in your project, add the following Maven dependency to your build:
    <repository>
       <id>jboss</id>
       <url>http://repository.jboss.org/maven2</url>
    </repository>

       ...
    <dependency>
       <groupId>org.jboss.resteasy</groupId>
       <artifactId>resteasy-jackson-provider</artifactId>
       <version>1.1.GA</version>
    </dependency>
RESTEasy expands the JAX-RS integration built into Jackson in several ways. The first expansion provided support for application/*+json. Previously, Jackson accepted only application/json and text/json as valid media types. application/*+json support lets you marshal your JSON-based media types with Jackson. For example:
@Path("/customers")
public class MyService {

   @GET
   @Produces("application/vnd.customer+json")
   public Customer[] getCustomers() {}
}
Using RESTEasy JAXB providers alongside Jackson is also problematic. Rather than use Jackson to output your JSON, you can use Jettison and JAXB. To do so, you must either not install the Jackson provider, or use the @org.jboss.resteasy.annotations.providers.NoJackson annotation on your JAXB annotated classes, like so:
    @XmlRootElement
    @NoJackson
    public class Customer {...}

    @Path("/customers")
    public class MyService {

       @GET
       @Produces("application/vnd.customer+json")
       public Customer[] getCustomers() {}
    }
If you cannot annotate the JAXB class with @NoJackson, tehn you can annotate a method parameter instead:

        @XmlRootElement
        public class Customer {...}

        @Path("/customers")
        public class MyService {

           @GET
           @Produces("application/vnd.customer+json")
           @NoJackson
           public Customer[] getCustomers() {}

           @POST
           @Consumes("application/vnd.customer+json")
           public void createCustomer(@NoJackson Customer[] customers) {...}
        }

19.1. Possible Conflict With JAXB Provider

If your Jackson classes are annotated with JAXB annotations and the resteasy-jaxb-provider is on your classpath, you can trigger the Jettison JAXB marshalling code. To disable the JAXB JSON Marshaller, annotate your classes with @org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes("application/*+json").