title: Unable to Produce JSON - javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException
body: <p>Am using Jersey 1.15, JDK 1.6, Tomcat 7, Maven 2.2.1 to create a simple Restful Web Service that should return a JSON String from a POJO that I mapped.</p>
  
  <p>Here's my pojo:</p>
  
  <pre><code>package com.myservice.domain;
  
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class Person {
     private String firstName;
     private String lastName;
  
    // Getters &amp; Setters
  }
  </code></pre>
  
  <p>my webservice:</p>
  
  <pre><code>package com.myservice.resource;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  import com.myservice.domain.Person;
  
  @Path("/service")
  public class MyService {
  
      @GET
      @Path("showPerson")
      @Produces(MediaType.APPLICATION_JSON)
      public Person getPerson() {
         Person person = new Person();
         person.setFirstName("John");
         person.setLastName("Doe");
         return person;
      }
  }
  </code></pre>
  
  <p>Here's my pom.xml:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0    
           http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  
           &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
           &lt;groupId&gt;com.myservice&lt;/groupId&gt;
           &lt;artifactId&gt;myservice&lt;/artifactId&gt;
           &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
           &lt;packaging&gt;war&lt;/packaging&gt;
           &lt;name&gt;My Web Service&lt;/name&gt;
  
           &lt;dependencies&gt;
               &lt;dependency&gt;
                   &lt;groupId&gt;junit&lt;/groupId&gt;
                   &lt;artifactId&gt;junit&lt;/artifactId&gt;
                   &lt;version&gt;4.8.2&lt;/version&gt;
                   &lt;scope&gt;test&lt;/scope&gt;
               &lt;/dependency&gt;
  
               &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-servlet&lt;/artifactId&gt;
                  &lt;version&gt;1.15&lt;/version&gt;
                  &lt;scope&gt;runtime&lt;/scope&gt;
               &lt;/dependency&gt;
  
              &lt;dependency&gt;
                 &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                 &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
                 &lt;version&gt;1.15&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                    &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                    &lt;artifactId&gt;jersey-core&lt;/artifactId&gt;
                    &lt;version&gt;1.15&lt;/version&gt;
              &lt;/dependency&gt;
  
              &lt;dependency&gt;
                   &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                   &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
                   &lt;version&gt;1.14&lt;/version&gt;
              &lt;/dependency&gt;
  
             &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-multipart&lt;/artifactId&gt;
                  &lt;version&gt;1.14&lt;/version&gt;
             &lt;/dependency&gt;
  
             &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.9&lt;/version&gt;
             &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
       &lt;build&gt;
            &lt;finalName&gt;myservice&lt;/finalName&gt;
            &lt;plugins&gt;
                  &lt;plugin&gt;
                   &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                    &lt;configuration&gt;
                         &lt;source&gt;1.6&lt;/source&gt;
                         &lt;target&gt;1.6&lt;/target&gt;
                    &lt;/configuration&gt;
                  &lt;/plugin&gt;
            &lt;/plugins&gt;
       &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>My web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                               http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0"
           metadata-complete="true"&gt;
       &lt;display-name&gt;My Web Service&lt;/display-name&gt;
       &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.myservice.resource&lt;/param-value&gt;
           &lt;/init-param&gt;
           &lt;init-param&gt;
              &lt;param-name&gt;com.sun.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
              &lt;param-value&gt;true&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;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>After deploying to tomcat, when I try to invoke the web service like this:</p>
  
  <pre><code>curl -X GET http://localhost:8080/myservice/rest/service/showPerson
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Nov 20, 2012 10:40:06 AM com.sun.jersey.spi.container.ContainerResponse write
  SEVERE: A message body writer for Java class com.myservice.domain.Person, 
  and Java type class com.myservice.domain.Person, 
  and MIME media type application/json was not found
  
  Nov 20, 2012 10:40:06 AM com.sun.jersey.spi.container.ContainerResponse write
  SEVERE: A message body writer for Java class com.myservice.domain.Person,
  and Java type class com.myservice.domain.Person, and MIME media type 
  application/json was not found
  
  Nov 20, 2012 10:40:06 AM com.sun.jersey.spi.container.ContainerResponse write 
  SEVERE: The registered message body writers compatible with the 
  MIME media type are: */* -&gt;
  
       com.sun.jersey.core.impl.provider.entity.FormProvider
       com.sun.jersey.core.impl.provider.entity.StringProvider
       com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
       com.sun.jersey.core.impl.provider.entity.FileProvider
       com.sun.jersey.core.impl.provider.entity.InputStreamProvider
       com.sun.jersey.core.impl.provider.entity.DataSourceProvider
       com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
       com.sun.jersey.core.impl.provider.entity.ReaderProvider
       com.sun.jersey.core.impl.provider.entity.DocumentProvider
       com.sun.jersey.core.impl.provider.entity.StreamingOutputProviderfg
       com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
       com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
       com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
       com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  
      Nov 20, 2012 10:40:06 AM com.sun.jersey.spi.container.ContainerResponse 
      write
  
        SEVERE: The registered message body writers compatible with the 
        MIME media type are:
        */* -&gt;
  
       com.sun.jersey.core.impl.provider.entity.FormProvider
       com.sun.jersey.core.impl.provider.entity.StringProvider
       com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
       com.sun.jersey.core.impl.provider.entity.FileProvider
       com.sun.jersey.core.impl.provider.entity.InputStreamProvider
       com.sun.jersey.core.impl.provider.entity.DataSourceProvider
       com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
       com.sun.jersey.core.impl.provider.entity.ReaderProvider
       com.sun.jersey.core.impl.provider.entity.DocumentProvider
       com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
       com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
       com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
       com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
       com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  
      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
      com.myservice.domain.Person, 
      and Java type class com.myservice.domain.Person, 
      and MIME media type application/json was not found
  
      com.sun.jersey.api.MessageException: 
  
      A message body writer for Java class com.myservice.domain.Person, 
      and Java type class com.myservice.domain.Person, and MIME media type  
      application/json was not found
  
      HTTP Status 500 - Internal Server Error 
      The server encountered an internal error that prevented it from 
      fulfilling this request.
  </code></pre>
  
  <p>After scouring the Internet, I tried inserting the following proposed solution that everyone suggested into web.xml:</p>
  
  <pre><code>&lt;init-param&gt;
     &lt;param-name&gt;com.sun.jersey.api.json.POJOMappingFeature&lt;/param-name&gt;
     &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/init-param&gt;
  </code></pre>
  
  <p>But it still gives me the same issue! It does return the correct data marshalled to XML if I use APPLICATION_XML, however.</p>
  
  <p>Would really appreciate it if someone could point me in the right direction.</p>
  
  <p>Thank you very much for taking the time to read this.</p>