title: Jersey rest server - Return list as json
body: <p>I'm experiencing a difference in the json structure of a returned list running the same code when running on Tomcat and Glassfish.</p>
  
  <pre><code>@XmlRootElement
  public Class Person {
      private int personId;
      private String name;
  }
  
  @GET
  @Path("/persons")
  public Response getPersons()
  {
      List&lt;Person&gt; persons = new ArrayList&lt;Person&gt;();
      persons.add(new Person(1, "John Smith"));
      persons.add(new Person(2, "Jane Smith"));
  
      GenericEntity&lt;List&lt;Person&gt;&gt; entity = new GenericEntity&lt;List&lt;Person&gt;&gt;(Lists.newArrayList&lt;persons)) {};
      Return Response.ok(entity).build();
  }
  </code></pre>
  
  <p>If returned in json format on tomcat (I'm running Tomcat on local machine) the result will be:</p>
  
  <pre><code>[
      {
          "personId" : "1",
          "name" : "John Smith"
      },
      {
          "personId" : "2",
          "name" : "Jane Smith"
      }
  ]
  </code></pre>
  
  <p>And if returned in json format on Glassfish (running Glassfish on remote server) the result will be:</p>
  
  <pre><code>{
      "person" : 
      [
          {
              "personId" : "1",
              "name" : "John Smith"
          },
          {
              "personId" : "2",
              "name" : "Jane Smith"
          }
      ]
  }
  </code></pre>
  
  <p>How can I control this format my self? I would prefer the array-format (as on Tomcat) if possible. Either way I want it to produce the same result.</p>
  
  <p>Edit:</p>
  
  <p>Dependencies: 
  jersey-container-servlet (2.14), 
  jersey-server (2.14), 
  jersey-media-moxy (2.14), 
  javax.servlet-api (3.0.1)</p>
  
  <p>Version of Glassfish: 3.1.2.2 (build 5)</p>
  
  <p>Edit 2:
  It's a problem with Jersey 2.14 and Glassfish 3.x</p>
  
  <p>I just installed Glassfish 3 and 4 and deployed the rest app to check the response. It resulted in different json structure when returning a list. The response from Glassfish 4 was identical to the result I got when running on Tomcat.</p>