title: RestController JSON Response object format
body: <p>I am using Spring Boot to return data from a Repository.  I would like to format my JSON so that it plays nicely with ExtJS' ajax handling.  Essentially I would like to include properties to handle success/failure, count, and errorMsg along with a List of data from the repository.</p>
  
  <p>I have tried by creating a ResponseDTO object that I'm returning from my Rest Controller.</p>
  
  <pre><code>@RestController
  public class AdminController {
  
      private static final Logger logger = LogManager.getLogger(AdminController.class);
  
      @Autowired
      private UserService userService;
  
      @Autowired
      private SecurityService securityService;
  
      @Autowired
      private UserValidator userValidator;
  
      @GetMapping("/searchUsers")
      public ResponseDTO searchUsers(String name, String active) {
          int activeFlag;
          List&lt;User&gt; users;
          ResponseDTO resp;
          if(active.equals("true")) {
              activeFlag = 1;
          } else activeFlag=0;
  
          if(StringUtils.isEmpty(name)) {
              users= userService.findAllUsers(activeFlag);
          } else {
              users= userService.findByUsernameActive(name, activeFlag);
          }   
  
          return new ResponseDTO(users, true);
      }
  }
  </code></pre>
  
  <p>Here's my DTO that I use in the controller:</p>
  
  <pre><code>public class ResponseDTO {
      private boolean success;
      private int count = 0;
  
      private List&lt;?&gt; values;
  
      public boolean getSuccess() {
          return this.success;
      }
      public void setState(boolean st) {
          this.success=st;
      }
      public int getCount() {
          return this.count;
      }
      public void setCount(int cnt) {
          this.count=cnt;
      }
  
      public List&lt;?&gt;getValues() {
          return this.values;
      }
      public void setValues(List&lt;?&gt; vals) {
          this.values = vals;
      }
  
      public ResponseDTO(List&lt;?&gt; items, boolean state) {
          this.success = state;
          values = items;
          this.count = items.size();
      }
  }
  </code></pre>
  
  <p>Here's what the JSON I get back looks like:</p>
  
  <pre><code>{
    "ResponseDTO": {
                      "success":true,
                      "count":2,
                      "values":[{obj1 } , { obj2}]
                   }
  }
  </code></pre>
  
  <p>what I would like to get is something more like:</p>
  
  <pre><code>{
     "success" : true,
     "count" : 2,
     "values" [{obj1},{obj2}]
  }
  </code></pre>
  
  <p>I'm using Spring Boot and Jackson annotations.  I have used an annotation to ignore individual fields in the objects in the results array, but  I can't find a way to unwrap the ResponseDTO object to not include the class name.  </p>