如何在发送Map对象时设置json属性的顺序



我正在发送一个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());
}

如何控制JSON属性的顺序时返回一个地图对象?

LinkedHashMap保持插入顺序:

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

最新更新