<commit_before><chapter id="json">
    <title>JSON Support via Jackson</title>
    <para>Besides the Jettision JAXB adapter for JSON, Resteasy also support integration with the Jackson project.
        Many users find the output from Jackson much much nicer than the Badger format or Mapped format provided by
        Jettison.
        Jackson lives at http://jackson.codehaus.org. It allows you to easily marshal Java objects to and from JSON.
        It has a Java Bean based model as well as JAXB like APIs. Resteasy integrates with the JavaBean model as
        described
        at this url: http://jackson.codehaus.org/Tutorial.
    </para>
    <para>While Jackson does come with its own JAX-RS integration. Resteasy expanded it a little. To include
        it within your project, just add this maven dependency to your build.  Resteasy supports both Jackson 1.9.x
        and Jackson 2.2.x.  Read further on how to use each.
    </para>
    <sect1>
        <title>Using Jackson 1.9.x Outside of JBoss AS7</title>
        <para>If you're deploying Resteasy outside of JBoss AS7 add the resteasy jackson provder to your WAR
        pom.xml build</para>
        <programlisting><![CDATA[
    <dependency>
       <groupId>org.jboss.resteasy</groupId>
       <artifactId>resteasy-jackson-provider</artifactId>
       <version>3.0.11.Final-SNAPSHOT</version>
    </dependency>
 ]]></programlisting>
    </sect1>
    <sect1>
        <title>Using Jackson 1.9.x Inside of JBoss AS7</title>
        <para>If you're deploying Resteasy with JBoss AS7, there's nothing you need to do except to make sure
            you've updated your AS7 distribution with the latest and greatest Resteasy.  See the installation sectio
            of this documentation for more details.</para>
    </sect1>
    <sect1>
        <title>Using Jackson 2.2.x Outside of JBoss AS7</title>
        <para>If you're deploying Resteasy outside of JBoss AS7 add the resteasy jackson provder to your WAR
            pom.xml build</para>
        <programlisting><![CDATA[
    <dependency>
       <groupId>org.jboss.resteasy</groupId>
       <artifactId>resteasy-jackson2-provider</artifactId>
       <version>3.0.11.Final-SNAPSHOT</version>
    </dependency>
 ]]></programlisting>
    </sect1>
    <sect1>
        <title>Using Jackson 2.2.x Inside of JBoss AS7</title>
        <para>If you want to use Jackson 2.2.x inside of JBoss AS7 you'll have to create a jboss-deployment-structure.xml file
        within your WEB-INF directory.  By default AS7 includes the Jackson 1.9.x JAX-RS integration, so you'll want
        to exclude it from your dependencies, and add the jackson2 ones.</para>
        <programlisting><![CDATA[
<jboss-deployment-structure>
    <deployment>
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure> ]]></programlisting>
    </sect1>
    <sect1>
        <title>Additional Resteasy Specifics</title>

    <para>The first extra piece that Resteasy added to the integration was
        to support "application/*+json". Jackson would only accept "application/json" and "text/json" as valid
        media types. This allows you to create json-based media types and still
        let Jackson marshal things for you. For example:
    </para>
    <programlisting>
        <![CDATA[
@Path("/customers")
public class MyService {

   @GET
   @Produces("application/vnd.customer+json")
   public Customer[] getCustomers() {}
}
]]>
    </programlisting>
    <para>Another problem that occurs is when you are using the Resteasy JAXB providers alongside Jackson.
        You may want to use Jettison and JAXB to output your JSON instead of Jackson. In this case, you must
        either not install the Jackson provider, or use the annotation
        @org.jboss.resteasy.annotations.providers.NoJackson
        on your JAXB annotated classes. For example:
    </para>
    <programlisting>
        <![CDATA[

    @XmlRootElement
    @NoJackson
    public class Customer {...}

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

       @GET
       @Produces("application/vnd.customer+json")
       public Customer[] getCustomers() {}
    }
    ]]>
    </programlisting>
    <para>
        If you can't annotate the JAXB class with @NoJackson, then you can
        use the annotation on a method parameter. For example:
    </para>
    <programlisting>
        <![CDATA[

        @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) {...}
        }
        ]]>
    </programlisting>
    </sect1>
    <sect1 id="Possible_Jackson_Problems">
        <title>Possible Conflict With JAXB Provider</title>
        <para>
            If your Jackson classes are annotated with JAXB annotations and you have the resteasy-jaxb-provider in your
            classpath, you may trigger the Jettision JAXB marshalling code. To turn off the JAXB json marshaller
            use the @org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes("application/*+json") on your
            classes.
        </para>
    </sect1>
    <sect1 id="JSONP_Support">
        <title>JSONP Support</title>
        <para>
            If you're using Jackson, Resteasy has <ulink url="http://en.wikipedia.org/wiki/JSONP">JSONP</ulink> that you can turn on by adding
            the provider <literal>org.jboss.resteasy.plugins.providers.jackson.JacksonJsonpInterceptor</literal> (Jackson2JsonpInterceptor if you're using the Jackson2 provider)
            to your deployments.
            If the media type of the response is json and a callback query parameter is given, the response will be a javascript snippet with
            a method call of the method defined by the callback parameter.
            For example:
<programlisting>
GET /resources/stuff?callback=processStuffResponse
</programlisting>
            will produce this response:
<programlisting>
processStuffResponse(&lt;nomal JSON body&gt;)
</programlisting>
            This supports the default behavior of <ulink url="http://api.jquery.com/jQuery.ajax/">jQuery</ulink>.
        </para>
        <para>
            You can change the name of the callback parameter by setting the callbackQueryParameter property.
        </para>
    </sect1>
    <sect1 id="Jackson_JSON_Decorator">
        <title>Jackson JSON Decorator</title>
        <para>
            If you are using the Jackson 2.2.x provider, Resteasy has provided a pretty-printing annotation simliar with the one in JAXB provider:
<programlisting>
org.jboss.resteasy.annotations.providers.jackson.Formatted
</programlisting>
            Here is an example:
<programlisting>
@GET
@Produces("application/json")
@Path("/formatted/{id}")
@Formatted
public Product getFormattedProduct()
{
    return new Product(333, "robot");
}
</programlisting>
            As the example shown above, the @Formatted annotation will enable the underlying Jackson option "SerializationFeature.INDENT_OUTPUT".<commit_msg>Add instruction to enable JSONP in WildFly<commit_after><chapter id="json">
    <title>JSON Support via Jackson</title>
    <para>Besides the Jettision JAXB adapter for JSON, Resteasy also support integration with the Jackson project.
        Many users find the output from Jackson much much nicer than the Badger format or Mapped format provided by
        Jettison.
        Jackson lives at http://jackson.codehaus.org. It allows you to easily marshal Java objects to and from JSON.
        It has a Java Bean based model as well as JAXB like APIs. Resteasy integrates with the JavaBean model as
        described
        at this url: http://jackson.codehaus.org/Tutorial.
    </para>
    <para>While Jackson does come with its own JAX-RS integration. Resteasy expanded it a little. To include
        it within your project, just add this maven dependency to your build.  Resteasy supports both Jackson 1.9.x
        and Jackson 2.2.x.  Read further on how to use each.
    </para>
    <sect1>
        <title>Using Jackson 1.9.x Outside of JBoss AS7</title>
        <para>If you're deploying Resteasy outside of JBoss AS7 add the resteasy jackson provder to your WAR
        pom.xml build</para>
        <programlisting><![CDATA[
    <dependency>
       <groupId>org.jboss.resteasy</groupId>
       <artifactId>resteasy-jackson-provider</artifactId>
       <version>3.0.11.Final-SNAPSHOT</version>
    </dependency>
 ]]></programlisting>
    </sect1>
    <sect1>
        <title>Using Jackson 1.9.x Inside of JBoss AS7</title>
        <para>If you're deploying Resteasy with JBoss AS7, there's nothing you need to do except to make sure
            you've updated your AS7 distribution with the latest and greatest Resteasy.  See the installation sectio
            of this documentation for more details.</para>
    </sect1>
    <sect1>
        <title>Using Jackson 2.2.x Outside of JBoss AS7</title>
        <para>If you're deploying Resteasy outside of JBoss AS7 add the resteasy jackson provder to your WAR
            pom.xml build</para>
        <programlisting><![CDATA[
    <dependency>
       <groupId>org.jboss.resteasy</groupId>
       <artifactId>resteasy-jackson2-provider</artifactId>
       <version>3.0.11.Final-SNAPSHOT</version>
    </dependency>
 ]]></programlisting>
    </sect1>
    <sect1>
        <title>Using Jackson 2.2.x Inside of JBoss AS7</title>
        <para>If you want to use Jackson 2.2.x inside of JBoss AS7 you'll have to create a jboss-deployment-structure.xml file
        within your WEB-INF directory.  By default AS7 includes the Jackson 1.9.x JAX-RS integration, so you'll want
        to exclude it from your dependencies, and add the jackson2 ones.</para>
        <programlisting><![CDATA[
<jboss-deployment-structure>
    <deployment>
        <exclusions>
           <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
        </exclusions>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure> ]]></programlisting>
    </sect1>
    <sect1>
        <title>Additional Resteasy Specifics</title>

    <para>The first extra piece that Resteasy added to the integration was
        to support "application/*+json". Jackson would only accept "application/json" and "text/json" as valid
        media types. This allows you to create json-based media types and still
        let Jackson marshal things for you. For example:
    </para>
    <programlisting>
        <![CDATA[
@Path("/customers")
public class MyService {

   @GET
   @Produces("application/vnd.customer+json")
   public Customer[] getCustomers() {}
}
]]>
    </programlisting>
    <para>Another problem that occurs is when you are using the Resteasy JAXB providers alongside Jackson.
        You may want to use Jettison and JAXB to output your JSON instead of Jackson. In this case, you must
        either not install the Jackson provider, or use the annotation
        @org.jboss.resteasy.annotations.providers.NoJackson
        on your JAXB annotated classes. For example:
    </para>
    <programlisting>
        <![CDATA[

    @XmlRootElement
    @NoJackson
    public class Customer {...}

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

       @GET
       @Produces("application/vnd.customer+json")
       public Customer[] getCustomers() {}
    }
    ]]>
    </programlisting>
    <para>
        If you can't annotate the JAXB class with @NoJackson, then you can
        use the annotation on a method parameter. For example:
    </para>
    <programlisting>
        <![CDATA[

        @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) {...}
        }
        ]]>
    </programlisting>
    </sect1>
    <sect1 id="Possible_Jackson_Problems">
        <title>Possible Conflict With JAXB Provider</title>
        <para>
            If your Jackson classes are annotated with JAXB annotations and you have the resteasy-jaxb-provider in your
            classpath, you may trigger the Jettision JAXB marshalling code. To turn off the JAXB json marshaller
            use the @org.jboss.resteasy.annotations.providers.jaxb.IgnoreMediaTypes("application/*+json") on your
            classes.
        </para>
    </sect1>
    <sect1 id="JSONP_Support">
        <title>JSONP Support</title>
        <para>
            If you're using Jackson, Resteasy has <ulink url="http://en.wikipedia.org/wiki/JSONP">JSONP</ulink> that you can turn on by adding
            the provider <literal>org.jboss.resteasy.plugins.providers.jackson.JacksonJsonpInterceptor</literal> (Jackson2JsonpInterceptor if you're using the Jackson2 provider)
            to your deployments.
            If the media type of the response is json and a callback query parameter is given, the response will be a javascript snippet with
            a method call of the method defined by the callback parameter.
            For example:
<programlisting>
GET /resources/stuff?callback=processStuffResponse
</programlisting>
            will produce this response:
<programlisting>
processStuffResponse(&lt;nomal JSON body&gt;)
</programlisting>
            This supports the default behavior of <ulink url="http://api.jquery.com/jQuery.ajax/">jQuery</ulink>.
            To enable JacksonJsonpInterceptor in WildFly, you need to import annotations from <literal>org.jboss.resteasy.resteasy-jackson-provider</literal> module using jboss-deployment-structure.xml:
<programlisting><![CDATA[
<jboss-deployment-structure>
  <deployment>
    <dependencies>
      <module name="org.jboss.resteasy.resteasy-jackson-provider" annotations="true"/>
    </dependencies>
  </deployment>
</jboss-deployment-structure>
]]></programlisting>
        </para>
        <para>
            You can change the name of the callback parameter by setting the callbackQueryParameter property.
        </para>
    </sect1>
    <sect1 id="Jackson_JSON_Decorator">
        <title>Jackson JSON Decorator</title>
        <para>
            If you are using the Jackson 2.2.x provider, Resteasy has provided a pretty-printing annotation simliar with the one in JAXB provider:
<programlisting>
org.jboss.resteasy.annotations.providers.jackson.Formatted
</programlisting>
            Here is an example:
<programlisting>
@GET
@Produces("application/json")
@Path("/formatted/{id}")
@Formatted
public Product getFormattedProduct()
{
    return new Product(333, "robot");
}
</programlisting>
            As the example shown above, the @Formatted annotation will enable the underlying Jackson option "SerializationFeature.INDENT_OUTPUT".
{'fraction_non_alphanumeric': 0.09250502040551921, 'fraction_numerical': 0.007643972274405649, 'mean_word_length': 2.809970384995064, 'pattern_counts': {'":': 0, '<': 249, '<?xml version=': 0, '>': 249, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7314036', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4205, 'n_words': 1449}