title: How to return custom response in Spring with several attributes other than the List<Entity>
body: <p>I'm trying to get a custom response back from a spring rest controller back to the user, containing a list of all registered users and other keys such as sucess, etc.
  I tried the following approach but the Json array is completly escaped as a string...</p>
  <pre><code>@GetMapping(value = &quot;/workers&quot;, produces = &quot;application/json;charset=UTF-8&quot;)
  public ResponseEntity&lt;String&gt; getAllWorkers() throws JSONException {
      JSONObject resp = new JSONObject();
      ObjectMapper objectMapper = new ObjectMapper();
  
      HttpStatus status;
      try {
          ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
          List&lt;Worker&gt; workers = workerservice.getAllworkers();
          String json = mapper.writeValueAsString(workers);
          
          resp.put(&quot;success&quot;, true);
          resp.put(&quot;info&quot;, json);
          status = HttpStatus.OK;
      } catch (Error | JsonProcessingException e) {
          resp.put(&quot;success&quot;, false);
          resp.put(&quot;info&quot;, e.getMessage());
          status = HttpStatus.INTERNAL_SERVER_ERROR;
      }
  
      return new ResponseEntity&lt;&gt;(resp.toString(),status);
  }
  </code></pre>
  <p>I get something like this</p>
  <pre><code>{
      &quot;success&quot;: true,
      &quot;info&quot;: &quot;[ {\n  \&quot;id\&quot; : 3,\n  \&quot;password\&quot; : \&quot;abcdefg\&quot;, \n  \&quot;tasks\&quot; : [ ], (...) ]&quot;
  }
  </code></pre>
  <p>and wanted something like:</p>
  <pre><code>{
      &quot;success&quot;: true,
      &quot;info&quot;: [ 
          {
             &quot;id&quot; : 3,
             &quot;password&quot; : &quot;abcdefg&quot;,
             &quot;tasks&quot; : [ ]
          },
          (...) 
      ]&quot;
  }
  </code></pre>
  <p>Is there any way I can get the json array properly showed after a request?</p>