Home > Net >  How to set the order of json properties when sending a Map object [duplicate]
How to set the order of json properties when sending a Map object [duplicate]

Time:09-17

I am sending a HashMap object as response from my RestController.

@GetMapping("/balance")
    public Map<String, Object>  fetchAccountsByBalance(){
         Map<String, Object> response = new HashMap<>();
         response.put("records", totalNumberOfRecords);
         response.put("pages", totalPages);
         response.put("data", pageResponse.getContent());
}

How to control the order of JSON properties when returning a Map object?

CodePudding user response:

LinkedHashMap maintains insertion order:

Map<String, Object> response = new LinkedHashMap<>();
  • Related