title: Jersey response for empty list is null instead of {}
body: <p>I have a JAX-RS REST service using Jersey. I use JAXB for JSON marshalling (ie. @XmlRootElement)
  One of the method returns a list of objects persisted with JPA. </p>
  
  <p>When this list contains entries it works as I expect. Example:</p>
  
  <pre><code>{"androidDevice":[{"email":"dagfinn.parnas@d2.no","timeCreated":"2012-10-19T
  22:41:26.862+02:00"},{"email":"dagfinn.parnas@d1.com","timeCreated":"2012-10-
  19T22:41:38.093+02:00"}]}
  </code></pre>
  
  <p>However, if the list is empty (or null) I would expect it to return {}.</p>
  
  <p>Instead it returns null. Example:</p>
  
  <pre><code>$ curl  -i -H "Accept: application/json" http://....
  HTTP/1.1 200 OK
  Content-Type: application/json
  
  null
  </code></pre>
  
  <p>Here is the code</p>
  
  <pre><code>    @GET
  @Produces( { MediaType.APPLICATION_JSON ,  MediaType.APPLICATION_XML})
  public List&lt;AndroidDevice&gt; getAndroidDevices() {
      logger.info("getAndroidDevices method called");
  
  
      EntityManager entityManager = entityMangerFactory.createEntityManager();  
      List&lt;AndroidDevice&gt; resultList = entityManager.createNamedQuery(AndroidDevice.QUERY_ALL_ENTRIES,  
              AndroidDevice.class).getResultList();  
  
      //avoid returning content null. (doesn't work)
      if(resultList==null){
          resultList=new ArrayList&lt;AndroidDevice&gt;();
      }
  
      return resultList;
  }
  </code></pre>
  
  <p>Is there any way to get Jersey to return an empty JSON list (besides hardcoding a ResponseBuilder) ? </p>
  
  <p>Should I instead provide a different response code for such events?</p>
  
  <p>Update: Got a tips through twitter about this bug report which concludes with that they won't fix it <a href="http://java.net/jira/browse/JERSEY-339" rel="nofollow">http://java.net/jira/browse/JERSEY-339</a></p>
  
  <p>Update2: 
  In addition to the solution below, since I was using an Application for configuration (refered to in web.xml), I had to manually add the Provider class there. Here is the relevant code.</p>
  
  <pre><code>public class JAXRSApplication extends Application {
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; set = new HashSet&lt;Class&lt;?&gt;&gt;();
          //Add all endpoints to this set
          set.add(AndroidDeviceEndpoint.class);
          //Add Providers
          set.add(JAXBContextResolver.class);
          return set;
      }   
  }
  </code></pre>