Java Jackson org.codehaus.jackson.map.exc.UnrecognizedPropertyException

I am linking a JSON response to my class using Jackson. Everything works fine except when there are more fields in my JSON response than my class defines. I want Jackson to ignore fields that do not exist in my JSON response. This is due to compatibility for future versions. If I add a new field, I do not want previous versions of my client to crash.

Ideas?

ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
        PromoResponse promoResponse = mapper.readValue(r, PromoResponse.class);
+3
source share
2 answers

You can put the annotation @JsonIgnoreProperties(ignoreUnknown=true)in your PromoResponse class.

+9
source

I believe that you will want to do something like this after declaring your mapper object:

mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

Dan

+5
source

All Articles