java - jackson 冲突的属性(property)和 setter/getter 定义

标签 java json serialization jackson

我正在扩展以下我无法更改的第三方类:

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 类的实例时,出现以下异常:

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)])

有没有一种简单的方法可以强制序列化程序生成“我的内容”属性?

最佳答案

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

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

关于java - jackson 冲突的属性(property)和 setter/getter 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30123656/

相关文章:

serialization - 使用 Protobuf-Net 在运行时创建 TypeModel,意外的子类型

java - 在 Java 的 HashSets 上使用方法 retainAll 的时间和空间复杂度是多少?

json - 如何在 JQ 中有条件地将字符串值更改为数字?

java - 由 : org. codehaus.jackson.map.JsonMappingException : Can not deserialize instance of com. model.user 超出 START_ARRAY token 引起

python - 接收 "TypeError: the JSON object must be str, bytes or bytearray, not dict"

python - 使用 Cython 时,可以替代在 PySpark mapPartitions 中使用嵌套函数吗?

java - NoClassDeFoundError WSServletContextListener 和 XMLStreamBuffer

java - 使用 Intent 将 TikTok 应用打开至其主页

java - 我们如何将参数值从 Jenkins 作业传递到 pom.xml,然后再传递到 JAVA 代码中的系统属性?

jQuery:表单序列化、隐藏字段和不显示字段