title: How do you return JSON from REST call?
body: <p>this may be a stupid question, but I couldn't find a clear answer on the web.
  I'm building a REST api with javax.ws.rs. 
  I've got a class that looks like this</p>
  
  <pre><code>public class Person{
  
      private String name;
  
      private List&lt;Telephone&gt; telephones;
  
      constructor + getters + setters
  }
  </code></pre>
  
  <p>I'm implementing a getAllPerson REST call that should return json. This is what I'm doing right now:</p>
  
  <pre><code>Path("/persons")
  @GET
  @Produces({MediaType.APPLICATION_JSON})
  public List&lt;Person&gt; getAllPersons() {
      return facade.getAllPersons();
  }
  </code></pre>
  
  <p>I don't think this is the right way to do it, because it gives me an error (HTTP Status 500 - Internal Server Error...) </p>
  
  <p>And I also have no idea how the program would know how to convert a list of person objects that contains another list of telephone objects to JSON. </p>
  
  <p>So what is the right way to return a list like that in JSON, should I manually build the json String? And what should the return type of the getAllPersons() be?</p>
  
  <p>Sorry if this is a really stupid question, but I couldn't find an answer that was clear to me.
  Thanks in advance.</p>
  
  <p>EDIT:
  The error I got is:</p>
  
  <pre><code>Severe:   MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List&lt;com.myproject.domain.Person&gt;.
  </code></pre>
  
  <p>EDIT2:
  I've added 
  @XmlRootElement to my Person class and I added an empty constructor</p>
  
  <p>I also added this to my pom file:</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.6.4&lt;/version&gt;
   &lt;/dependency&gt;
  </code></pre>