问题
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