发送Map对象时如何设置json属性的顺序
How to set the order of json properties when sending a Map object
我正在发送一个 HashMap 对象作为我的 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());
}
返回Map对象时如何控制JSON属性的顺序?
LinkedHashMap
维护插入顺序:
Map<String, Object> response = new LinkedHashMap<>();
我正在发送一个 HashMap 对象作为我的 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());
}
返回Map对象时如何控制JSON属性的顺序?
LinkedHashMap
维护插入顺序:
Map<String, Object> response = new LinkedHashMap<>();