ksonFeature打破了JsonIgnoreProperti

ksonFeature打破了JsonIgnoreProperti

本文介绍了JacksonFeature打破了JsonIgnoreProperties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的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 回复包含很多额外字段。

and my Jersey client works just fine even though the ConsumerProfile responses contain a lot of extra fields.

然后我添加一行:

client.register(JacksonFeature.class);

到我的Jersey客户端设置。之后,忽略不再起作用:

to my Jersey Client setup. And after that, the ignore's don't work anymore:

Unrecognized field "authService" (Class com.xyz..SNAPIResponse$ConsumerProfile), not marked as ignorable

为什么?

推荐答案

我偶然发现了这篇文章,帮助我让JsonIgnoreProperties再次运作:

I stumbled across this post which helped me get JsonIgnoreProperties working again: http://jersey.576304.n2.nabble.com/Beware-of-JacksonFeature-in-Jersey-td7581633.html

我没有足够的研究来100%确定问题的根本原因,但似乎注册JacksonFeature.class会引入一个过时版本的库。

I didn't research enough to be 100% sure on the underlying cause of the issue, but it seems registering JacksonFeature.class pulls in an outdated version of a library needed for this.

按照该链接的建议行事对我有用。

Doing as suggested in that link worked for me.

这篇关于JacksonFeature打破了JsonIgnoreProperties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:04