Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

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>
Copy to Clipboard Toggle word wrap
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() {}
}
Copy to Clipboard Toggle word wrap
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() {}
    }
Copy to Clipboard Toggle word wrap
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) {...}
        }
Copy to Clipboard Toggle word wrap

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").
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat