title: how to return json objects from java rest api
body: <p>I am trying to return a JSON object from a jax-rs but I get an internal server error whenever I try to access. </p>
  
  <p>This is my method, I am using <code>javax.ws.rs.GET</code>.</p>
  
  <pre><code>@GET
  @Produces("application/json")
  public Testy getJson() {
     return new Testy("hello");
  }
  </code></pre>
  
  <p>This is the class:</p>
  
  <pre><code>public class Testy {
  
      private final String value;
  
      public Testy(String value){
  
          this.value = value;
      }
  
    public String getValue(){
  
        return value;
     }
  
  }
  </code></pre>
  
  <p>My Pom.xml has this dependency, I have tried various dependencies, but none work. There are various maven resources for jersey, there's jersey-client jersey-core.</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.3.3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I am using Glassfish 4.</p>
  
  <p><strong>Questions about working with Jersey:</strong></p>
  
  <p>I have seen some <a href="https://jersey.java.net/documentation/1.18/json.html" rel="nofollow noreferrer">places</a> where they mention you need to have initialize POJO support, it seems like its for jersey 1.* but I am not sure. I don't need this if I am using 2.* ?</p>
  
  <p><a href="http://www.vogella.com/tutorials/REST/article.html" rel="nofollow noreferrer">Do I have to modify the web.xml to point to the jersey servlet ?</a> </p>
  
  <p><strong>How can I produce and consume JSON objects using POJO classes !?</strong> </p>
  
  <h1>Edit</h1>
  
  <p>Here is my auto generated config class. </p>
  
  <p><img src="https://i.stack.imgur.com/DivFb.png" alt="enter image description here"></p>