我收到警告消息:
com.fasterxml.jackson.databind.JsonMappingException: Conflicting/ambiguous property name definitions (implicit name 'balance'): found multiple explicit names: [{}Balance, Balance], but also implicit accessor: [method ResponseVO#getBalance(0 params)][visible=true,ignore=false,explicitName=false]
我有最新的 lombok 1.18.10 和 fasterxml.jackson-version 2.7.5
我找到了 similar issue但它应该在 2.7.4 中修复(关闭)
Jackson 2.7.1 and Lombok: 'Conflicting/ambiguous property name definitions' #1122
I think this can be changed for 2.7.4 after all, can fix this.
代码:
@Data
@AllArgsConstructor(access = AccessLevel.PUBLIC)
@NoArgsConstructor
public class ResponseVO implements Serializable {
private static final long serialVersionUID = 1;
@JacksonXmlProperty(localName = "Balance")
@JsonProperty("Balance")
@JacksonXmlElementWrapper(useWrapping = false)
List<BalanceResponseVO> balance;
是相关的警告吗?我该如何修复/删除此警告?
似乎新的 Lombok 版本也将 @JsonProperty("Balance")
添加到生成的 setter 中并造成了这种困惑
编辑
当我删除在我的情况下实际上不需要的 @JsonProperty("Balance")
时问题已解决
最佳答案
我们升级了 Lombok 版本,它现在添加了 @JsonProperty("Balance")
也生成了 setter
这个重复的 @JsonProperty
在日志中创建了一个 WARN,并且也未能创建响应(无一异常(exception))
我删除了 @JsonProperty("Balance")
这在我的案例中实际上是多余的/不需要的并且它有效
- 请注意更改为
private
并没有解决问题
FEATURE: Lombok now knows exactly how to treat @com.fasterxml.jackson.annotation.JsonProperty and will copy it to the right places for example when making builders. Issue #1961 Issue #1981
关于java - Lombok 和 jackson - 冲突/不明确的属性名称定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58689035/