gpt4 book ai didi

java - Jackson @JsonIgnore 改变了语义?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:18:55 24 4
gpt4 key购买 nike

我们刚刚升级了一些 Maven 依赖项,这触发了 Jackson 从 1.7.x 到 1.9.x 的更新

我们使用 @JsonIgnore 在 setter 方法上注释,在不应该从客户端设置的方法上。例如:对象的所有者(with 应该从身份验证主体中设置)等。

在我们看来,这个注释的语义已经改变了,这可能吗?现在该字段在所有情况下都被 jsonignored,而不仅仅是在设置时。

是这样吗? 1.9 中是否有替代方法来仅实现忽略 SET?

谢谢!

最佳答案

好的,我想我在 javadoc 中发现并明确提到了这个问题。 (jackson 的文档不容易看懂)。

In addition, starting with Jackson 1.9, if this is the only annotation associated with a property, it will also cause cause the whole property to be ignored: that is, if setter has this annotation and getter has no annotations, getter is also effectively ignored. It is still possible for different accessors to use different annotations; so if only "getter" is to be ignored, other accessors (setter or field) would need explicit annotation to prevent ignoral (usually JsonProperty).

关于java - Jackson @JsonIgnore 改变了语义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9299657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com