我从互联网上检索一个JSON字符串; 像大多数JSON我看到它包括由下划线分隔的长键.本质上,我的目标是将JSON反序列化为java对象,但我不在java代码中使用下划线.
例如,我可能在camel-case中有一个User
带firstName
字段的类,同时我需要以某种方式告诉Jackson将first_name
密钥从JSON 映射到firstName
类字段.可能吗?
class User{
protected String firstName;
protected String getFirstName(){return firstName;}
}
Run Code Online (Sandbox Code Playgroud) 杰克逊忽略了spring.jackson.property-naming-strategy = SNAKE_CASE.我正在使用springBootVersion 1.4.2.RELEASE.在我的application.properties文件中,我添加了
spring.jackson.property命名策略= SNAKE_CASE
但杰克逊并不尊重这个属性,我的REST响应仍然是camelCase.有趣的是,这个注释工作正常
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
有了这个注释,我得到了snake_case响应.但我不想对每个响应类进行注释,这有点烦人.
我也试过使用完全限定的类名,
spring.jackson.property命名策略= com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
这也没用
我在为 xPos、yPos、nCounter 等属性生成 getter/setter 时遇到问题。平台是 Eclipse Luna、Java 1.7、Struts2...
当 Eclipse 生成
private xPos
getXPos()
setXPos(...)
Run Code Online (Sandbox Code Playgroud)
Lombok 将生成
getxPos()
setxPos(...)
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉 Lombok 将每个第一个字符大写?