title: Spring: return @ResponseBody "ResponseEntity<List<JSONObject>>"
body: <p>In controller I create json array. If I return <code>List&lt;JSONObject&gt;</code> it is ok:</p>
  
  <pre><code>@RequestMapping(value="", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody List&lt;JSONObject&gt; getAll() {
      List&lt;Entity&gt; entityList = entityManager.findAll();
  
      List&lt;JSONObject&gt; entities = new ArrayList&lt;JSONObject&gt;();
      for (Entity n : entityList) {
          JSONObject entity = new JSONObject();
          entity.put("id", n.getId());
          entity.put("address", n.getAddress());
          entities.add(entity);
      }
      return entities;
  }
  </code></pre>
  
  <p>but I need to return JSON array and HTTP status code:</p>
  
  <pre><code>@RequestMapping(value="", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody ResponseEntity&lt;List&lt;JSONObject&gt;&gt; getAll() {
      List&lt;Entity&gt; entityList = entityManager.findAll();
  
      List&lt;JSONObject&gt; entities = new ArrayList&lt;JSONObject&gt;();
      for (Entity n : entityList) {
          JSONObject Entity = new JSONObject();
          entity.put("id", n.getId());
          entity.put("address", n.getAddress());
          entities.add(entity);
      }
      return new ResponseEntity&lt;JSONObject&gt;(entities, HttpStatus.OK); // XXX
  }
  </code></pre>
  
  <p>Eclipse see error in XXX line:</p>
  
  <pre><code>Multiple markers at this line
      - The constructor ResponseEntity&lt;JSONObject&gt;(List&lt;JSONObject&gt;, HttpStatus) is undefined
      - Type mismatch: cannot convert from ResponseEntity&lt;JSONObject&gt; to 
       ResponseEntity&lt;List&lt;JSONObject&gt;&gt;
      - Type mismatch: cannot convert from ResponseEntity&lt;JSONObject&gt; to JSONObject
  </code></pre>
  
  <p>How can I return json+http reply? There is my working code for returning one json object + http status code:</p>
  
  <pre><code>@RequestMapping(value="/{address}", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody ResponseEntity&lt;JSONObject&gt; getEntity(@PathVariable("address") int address) {
      Entity n = entityManager.findByAddress(address);
      JSONObject o = new JSONObject();
      o.put("id", n.getId());
      o.put("address", n.getAddress());
      return new ResponseEntity&lt;JSONObject&gt;(o, HttpStatus.OK);
  }
  </code></pre>