I have a class that I'm using the Jersey Client to deserialize. This class has a method that looks like this:
public boolean isEmpty() {
return (code == null &&
label == null &&
codeSystem == null &&
codeSystemLabel == null &&
description == null &&
concept == null &&
alternateCode == null
);
There is no setter. As-is, this will throw this exception:
com.sun.jersey.api.client.ClientHandlerException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "empty" (Class com.app.models.CodedElementModel), not marked as ignorable
at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3b927d51; line: 1, column: 270] (through reference chain: com.app.models.LabOrderModel["code"]->com.app.models.CodedElementModel["empty"])
I've read this article, and it turns out I can fix this by putting this annotation on the CodedElementModel
class: @JsonIgnoreProperties(ignoreUnknown = true)
.
The problem is I have a lot of methods throwing this exception. Is there a way to configure the Jersey Client to act as if @JsonIgnoreProperties(ignoreUnknown = true)
is set on every class so I don't have to annotate them by hand? I don't want to have to change ~30 files by adding this annotation manually. This will prevent such errors in the future if someone adds a getter without a setter.
Here's how I'm creating my Jersey Client:
DefaultClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
I feel like that clientConfig
may have a setting to do this, but I'm not sure how to find it.