java - 强制 org.springframework.http.ResponseEntity.ok 保留 Pascal-case json
问题描述
我有一个返回 ResponseEntity 的 Rest Service,它有一个 HashMap,它包含从 findAll() JPA 操作返回的 List<> 作为值。
@GetMapping("/users")
public ResponseEntity getUsers() {
List<Users> users = userRepository.findAll();
var model = new HashMap<>();
model.put("data",users);
return ok(model);
}
HashMap 的键是 Pascal-case 格式(如“UserMail”),但是当其余服务返回时,它会将键转换为驼峰格式(“userMail”)。有没有办法防止它保持原始格式?
解决方案
如果您想将用户下的所有属性强制为 Pascal-case 格式。您可以尝试将 PropertyNamingStrategy 应用于该类
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
Class Users {
...
}
推荐阅读
- javascript - svelte 可以使用可组合的函数吗?
- table-plus - 如何在 TablePlus GUI 中编辑索引
- python-3.x - Mlflow - 空的工件文件夹
- ios - 在 Swift 中,我什么时候使用“while let”?
- r - 将 NA 分配给 R 中的矩阵条目
- jquery - Vue组件中js库所需的JQUery
- css - 在 WordPress 中做了一些事情
- c++ - 这个字符反转功能有什么问题?
- node.js - Nodejs - 错误 [ERR_HTTP_HEADERS_SENT]:在将标头发送到客户端后无法设置标头
- javascript - 如何更新已动态设置属性名称的属性值?