JacksonFeature breaks JsonIgnoreProperties

試著忘記壹切 提交于 2019-12-10 20:34:09

问题


I have pojo's like these:

@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;
    }
}

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

Then I add a line:

client.register(JacksonFeature.class);

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

Why?


回答1:


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

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.



来源:https://stackoverflow.com/questions/20698929/jacksonfeature-breaks-jsonignoreproperties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!