杰克逊冲突 属性 和 getter 定义

Jackson conflicting property and getter definitions

我正在扩展我无法更改的第三方 class:

public class Page {
    @JsonProperty("content")
    private String content;

    public String getContent() {};
}

我的 Page 实现如下所示:

public class MyPage extends Page {
    @JsonProperty("my-content")
    public String getContent() {return super.getContent()};
}

当我尝试序列化 MyPage class 的实例时,出现以下异常:

java.lang.IllegalStateException: Conflicting property name definitions:  
'content' (for [field com.test.Page#content]) 
vs
'my-content' (for [method com.test.MyPage#getContent(0 params)])

有没有简单的方法强制序列化程序生成 'my-content' 属性?

我想这个问题在 Jackson 2.4.0 中已经解决了。请勾选 https://github.com/FasterXML/jackson-databind/issues/193.

尝试将您的 Jackson 库更新到 2.4.0 或更高版本。