Reputation: 726
I am binding a JSON response to my class using Jackson. Everything works great except when there are more fields in my JSON response than my class defines. I want Jackson to ignore the fields that do not exist in my JSON response. This is due to compatability 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);
Upvotes: 3
Views: 3436
Reputation: 19040
You can put the @JsonIgnoreProperties(ignoreUnknown=true)
annotation on your PromoResponse class.
Upvotes: 9
Reputation: 3884
I believe you would want to do something like this after you declare your mapper object:
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-Dan
Upvotes: 5