我有这样的 pojo:
@JsonIgnoreProperties(ignoreUnknown = true)
public class SNAPIResponse {
public String status;
public String message;
public int errorCode;
public ConsumerProfile consumerProfile;
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ConsumerProfile {
public String accountId;
}
}
即使 ConsumerProfile
响应包含很多额外的字段,我的 Jersey 客户端也能正常工作。
然后我添加一行:
client.register(JacksonFeature.class);
到我的 Jersey 客户端设置。在那之后,忽略不再起作用:
Unrecognized field "authService" (Class com.xyz..SNAPIResponse$ConsumerProfile), not marked as ignorable
为什么?
最佳答案
我偶然发现这篇文章帮助我让 JsonIgnoreProperties 再次工作:http://jersey.576304.n2.nabble.com/Beware-of-JacksonFeature-in-Jersey-td7581633.html
我没有进行足够的研究以 100% 确定问题的根本原因,但似乎注册 JacksonFeature.class 会引入为此所需的库的过时版本。
按照该链接中的建议进行对我有用。
关于java - JacksonFeature 打破了 JsonIgnoreProperties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20698929/