Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've finally figured out how to do it, thanks to Tomee's great support. So...here it is!</p> <p>I'll start by explaining how this can be achieved in latest <a href="http://tomee.apache.org/download/tomee-1.6.0-snapshot.html" rel="noreferrer">Tomee 1.6 JAX-RS version</a>, which will soon be released as stable. It's very stable even now, by the way.</p> <p>Supposing you have a Maven Java EE 6 web app project (use NetBeans to generate one), here are the steps:<br> 1. Add Jackson dependency in pom.xml</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt; &lt;artifactId&gt;jackson-jaxrs&lt;/artifactId&gt; &lt;version&gt;1.9.13&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>2. Create openejb-jar.xml in WEB-INF (the folder with web.xml) containing:</p> <pre><code>&lt;openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1"&gt; &lt;pojo-deployment class-name="jaxrs-application"&gt; &lt;properties&gt; cxf.jaxrs.providers = org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider &lt;/properties&gt; &lt;/pojo-deployment&gt; &lt;/openejb-jar&gt; </code></pre> <p>For more info about this config see <a href="http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-td4657777.html" rel="noreferrer">1</a> and <a href="http://openejb.979440.n4.nabble.com/How-to-get-Tomee-JAX-RS-CXF-Jackson-1-9-Please-help-td4665580.html" rel="noreferrer">2</a><br> Edit from <strong>@rmannibucau</strong>: if you use a custom jaxrs Application subclass (with @ApplicationPath for instance) you'll set the qualified name of this class instead of "jaxrs-application" (which means the default application).<br> 3. Create a JAX-RS Resource that won't work without Jackson (example: a plain List):</p> <pre><code>import java.util.Arrays; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/jackson") public class Resource { @GET @Produces({MediaType.APPLICATION_JSON}) public Object sayHelloJson() { return Arrays.asList(new String[]{"Peter", "pan", "Ihihi"}); } } </code></pre> <p>4. Deploy on Tomee 1.6.0 JAX-RS edition and launch the app at: <code>http://localhost:8080/yourAppPath/jackson</code> This guide was tested with version 1.6.0 2013.10.24 on NetBeans 7.4.</p> <p>In case you want the latest Jackson, replace the previous dependency with the following:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt; &lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt; &lt;version&gt;2.2.3&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>and modify openejb-jar.xml to contain:</p> <pre><code>cxf.jaxrs.providers = com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider </code></pre> <p><strong>Tomee 1.5.2</strong><br> For this version, providers must be specified for each resource, so not at application level as in 1.6.0. More info can be found <a href="http://openejb.979440.n4.nabble.com/TomEE-1-5-and-Jackson-td4657777.html" rel="noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload