How to wrap JSON response in a parent object How to wrap JSON response in a parent object json json

How to wrap JSON response in a parent object


You could make a new Object to serialize:

class ResponseWrapper {    private List<User> elements;    ResponseWrapper(List<User> elements) {        this.elements = elements;    }}

Then return an instance of ResponseWrapper in your controller method:

   @RequestMapping(value = "/users", method = GET,produces = "application/xml")   @ResponseBody   public ResponseEntity<ResponseWrapper> getPartnersByDate(@RequestParam("type") String type, @RequestParam("id") String id) throws ParseException {   List<User> usersList = userService.getUsersByType(type);   ResponseWrapper wrapper = new ResponseWrapper(usersList);   return new ResponseEntity<ResponseWrapper>(wrapper, HttpStatus.OK);}