title: javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: JSON support in Java REST Webservices with Jersey
body: <p>Okay, this question has probably been asked before, but on all sites I've looked the explanation on "how to do this" tells me I'm doing it completely right.</p>
  
  <p>I know I'm not, as I get a 500 server error on my localhost tomcat and I get the following error in my server logs:</p>
  
  <pre><code>javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.myapp.domain.Location, and Java type class com.myapp.domain.Location, and MIME media type application/json was not found
  </code></pre>
  
  <p>So, what I'm trying to do is to develop a RESTful web service with Jersey (in Java). Everything is going fine, except for the fact that I want to return JSON. I can't find what I'm doing different from these people:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/20834640/how-to-send-response-as-json-in-jersey-rest">How to send response as JSON in Jersey Rest</a></li>
  <li><a href="http://www.jasonwhaley.com/blog/2011/01/18/multiple-content-types-in-jax-rs/" rel="nofollow noreferrer">http://www.jasonwhaley.com/blog/2011/01/18/multiple-content-types-in-jax-rs/</a></li>
  <li><a href="https://github.com/jasonray/jersey-starterkit/wiki/Serializing-a-POJO-to-xml-or-json-using-JAXB" rel="nofollow noreferrer">https://github.com/jasonray/jersey-starterkit/wiki/Serializing-a-POJO-to-xml-or-json-using-JAXB</a></li>
  <li><a href="https://github.com/jasonray/jersey-starterkit/wiki/Serializing-a-POJO-to-json-using-built-in-jersey-support" rel="nofollow noreferrer">https://github.com/jasonray/jersey-starterkit/wiki/Serializing-a-POJO-to-json-using-built-in-jersey-support</a></li>
  <li><a href="http://www.vogella.com/tutorials/REST/article.html" rel="nofollow noreferrer">http://www.vogella.com/tutorials/REST/article.html</a></li>
  </ul>
  
  <p>My POJO (Location) looks like this:</p>
  
  <pre><code>package com.myapp.domain;
  
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement()
  public class Location {
      private int id;
      private double longtitude;
      private double latitude;
  
      public Location() {
          new Location(-1, -1, -1);
      }
  
      public Location(double longtitude, double latitude) {
          new Location(-1, longtitude, latitude);
      }
  
      public Location(int id, double longtitude, double latitude) {
          this.id = id;
          this.longtitude = longtitude;
          this.latitude = latitude;
      }
  
      public void setID(int id) {
          this.id = id;
      }
  
      public void setLongtitude(double longtitude) {
          this.longtitude = longtitude;
      }
  
      public void setLatitude(double latitude) {
          this.latitude = latitude;
      }
  
      public int getID() {
          return this.id;
      }
  
      public double getLongtitude() {
          return this.longtitude;
      }
  
      public double getLatitude() {
          return this.latitude;
      }
  }
  </code></pre>
  
  <p>My resource looks like this:</p>
  
  <pre><code>package com.myapp.MyAPP;
  
  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 com.myapp.domain.Location;
  
  @Path("Locations")
  public class LocationInfo {
      @GET
      @Path("/get/{id}")
      @Produces(MediaType.APPLICATION_JSON)
      public Location getLocation(@PathParam("id") int id) {
          Location loc = new Location(3, 4.007391, 51.00237);
          return loc;
      }
  }
  </code></pre>
  
  <p>And this is my web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://java.sun.com/xml/ns/javaee" 
      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          id="WebApp_ID" 
          version="2.5"&gt;  
      &lt;display-name&gt;MyAPP&lt;/display-name&gt; 
      &lt;servlet&gt; 
              &lt;servlet-name&gt;MyAPP 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.myapp.MyAPP&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;MyAPP 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>I've got these libraries included: <code>asm-3.1.jar</code>, <code>jersey-client-1.17.1.jar</code>, <code>jersey-core-1.17.1.jar</code>, <code>jersey-json-1.17.1.jar</code>, <code>jersey-server-1.17.1.jar</code>, <code>jersey-servlet-1.17.jar</code>, <code>jsr11-api-1.1.1.jar</code></p>
  
  <p>The one who sees what I'm not seeing gets a beer. Or at least my eternal gratitude, cause I've been looking at this for way too long and I still can't see it.</p>