JsonProperty and lombok on Intellij



我遇到了一个问题,我的pojo使用lombok与jsonproperty注释创建。它不尊重json注释。而且,当我使用lombok构建器创建对象时,它使用对象上的字段名而不是json属性。

有人能帮我看看我在这里错过了什么。我刚开始使用lombok,所以我希望一些简单的东西。我正在Intellij上运行代码

@Data
@Builder
public class pojo {
@JsonProperty("grant_type")
private final String grantType = "xyz";
@JsonProperty("client_id")
private String clientId;
}   

这是@Builder的默认行为
如果我们想要setClientId的构建器,我们可以在@Builder中添加setterPrefix = "set"

@Data
@Builder(setterPrefix = "set")
public class pojo {
@JsonProperty("grant_type")
private final String grantType = "xyz";
@JsonProperty("client_id")
private String clientId;
}

@Data将生成一对setter/getter。但是setter是pojo的成员方法,而不是pojoBuilder的。
关于Builder的更多细节在这里。

最新更新