title: Jersey JSON serialization
body: <p>I set up an eclipse WebApp project and placed Jersey and Jackson JARs in the WEB-INF/lib directory.  I want to use JSON serialization but didn't manage to fix this error:</p>
  <pre><code>MessageBodyWriter not found for media type=application/json, type=class com.rest.Greeting, genericType=class com.rest.Greeting. I already googled much but all the solutions are updated or don't solve my issue. Here is the structure of my project:
  </code></pre>
  <p>The <strong>WEB-INF/lib</strong> folder contains following JARs:</p>
  <pre><code>aopalliance-repackaged-2.3.0-b10.jar
  asm-debug-all-5.0.2.jar
  cglib-2.2.2.jar
  datafactory-0.8.jar
  hk2-api-2.3.0-b10.jar
  hk2-locator-2.3.0-b10.jar
  hk2-utils-2.3.0-b10.jar
  jackson-annotations-2.4.0.jar
  jackson-core-2.4.0.jar
  jackson-databind-2.4.0.jar
  jackson-jaxrs-base-2.4.0.jar
  jackson-jaxrs-json-provider-2.4.0.jar
  jackson-module-jaxb-annotations-2.4.0.jar
  javassist-3.18.1-GA.jar
  javax.annotation-api-1.2.jar
  javax.inject-2.3.0-b10.jar
  javax.servlet-api-3.0.1.jar
  javax.ws.rs-api-2.0.1.jar
  jaxb-api-2.2.7.jar
  jersey-client.jar
  jersey-common.jar
  jersey-container-servlet-core.jar
  jersey-container-servlet.jar
  jersey-guava-2.13.jar
  jersey-server.jar
  org.osgi.core-4.2.0.jar
  osgi-resource-locator-1.0.1.jar
  persistence-api-1.0.jar
  validation-api-1.1.0.Final.jar
  </code></pre>
  <p><strong>web.xml</strong>:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot; id=&quot;WebApp_ID&quot; version=&quot;3.0&quot;&gt;
    &lt;display-name&gt;Rest Test&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;Greeting&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
          &lt;param-value&gt;com.rest&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Greeting&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/greet/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  <p><strong>Greeting.java</strong>:</p>
  <pre><code>@XmlRootElement
  @Path(&quot;/greeting&quot;)
  public class Greeting {
      
      private String greeting;
      
      public Greeting() {
          this.setGreeting(&quot;hello&quot;);
      }
      
      @GET
      @Produces(MediaType.TEXT_XML)   
      public Greeting sayHello() {
          return new Greeting();
      }
  
      public String getGreeting() {
          return greeting;
      }
  
      public void setGreeting(String greeting) {
          this.greeting = greeting;
      }
      
  }
  </code></pre>
  <p>The WebApp project is run in an embedded Tomcat v7 server (view &quot;Servers&quot; in eclipse).
  <strong>The request</strong>:</p>
  <pre><code>http://localhost:8080/com.rest/greet/greeting
  </code></pre>
  <p>As long as I use <strong>MediaType.TEXT_XML</strong> there is no error and the content looks like this:</p>
  <pre><code>&lt;greeting&gt;
  &lt;greeting&gt;hello&lt;/greeting&gt;
  &lt;/greeting&gt;
  </code></pre>
  <p>When I change MediaType to <strong>&quot;MediaType.APPLICATION_JSON&quot;</strong> then the following exception (as described above) is thrown. I already noticed that it depends on the annotation &quot;@XmlRootElement&quot; but there is not something like &quot;JsonRootElement&quot; and the jackson/genson APIs claim that it works out of the box (due to the auto registration mechanism). Do you have any idea how to fix it?</p>
  <p>Every help is very very appreciated!</p>