title: How to produce JSON output with Jersey 1.6 using JAXB
body: <pre><code>@XmlRootElement
  public class Todo {
      private String s = "test";
  
      public String getS() {
          return s;
      }
  
      public void setS(String s) {
          this.s = s;
      }
  
  }
  </code></pre>
  
  <p>and service: </p>
  
  <pre><code>@Path("/test")
  public class Service {
  
      @GET
      @Produces({MediaType.APPLICATION_JSON })
      public List&lt;Todo&gt; getAllGadgets() {
          return Arrays.asList(new Todo[] { new Todo() });
      }
  
  }
  </code></pre>
  
  <p>my web.xml: </p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
          &lt;param-value&gt;com.test&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;Jersey REST Service&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>All this work if I set  MediaType.APPLICATION_XML for Produces annotation. But for JSON I get the following exception: </p>
  
  <blockquote>
    <p>SEVERE: Mapped exception to response:
    500 (Internal Server Error)
    javax.ws.rs.WebApplicationException:
    com.sun.jersey.api.MessageException: A
    message body writer for Java class
    java.util.Arrays$ArrayList, and Java
    type java.util.List,
    and MIME media type application/json
    was not found</p>
  </blockquote>
  
  <p>I use Jersey 1.6 and, according to the tutorial, JSON format should work with JAXB without any additional programming. What's wrong? </p>