泽西岛/杰克逊@JsonIgnore on setter

2024-01-20

我有一个带有以下注释的类:

class A {
public Map<String,List<String>> references;

@JsonProperty
public Map<String,List<String>> getReferences() {
...
}

@JsonIgnore
public void setReferences(Map<String,List<String>>) {
}
...
}
}

我尝试的是忽略反序列化时的 json。但这不起作用。当 JSON 字符串到达​​时,Jackson 库总是会填充引用属性。如果我只使用 @JsonIgnore 注释,则 getter 不起作用。对于这个问题有什么解决办法吗?

Thanks


从 Jackson 2.6 开始,有一种新的、改进的方法来定义read-only and write-only属性,使用JsonProperty#access() https://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonProperty.Access.html注解。建议使用单独的JsonIgnore and JsonProperty注释。

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public Map<String,List<String>> references;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

泽西岛/杰克逊@JsonIgnore on setter 的相关文章

随机推荐