1

This SO question explains how to ignore extra fields when deserializing JSON with Jackson by using @JsonIgnoreProperties(ignoreUnknown=true), but I want to know when/why should I do this?

This overrides the default for Jackson, which is to throw an exception for unexpected fields. I assume if I should just use this default normally, but when/why would I want to design my system to be strict vs accept anything it can?

I guess this is more of a design philosophy question, so let me know if this is not the right place to ask.

dongle man
  • 133
  • 1
  • 7

1 Answers1

2

The SO question itself has one of the scenarios as an answer to this question.

The problem is, the JSON objects might change and have new fields added while the application is published, but currently it will break even when a simple String field is added, which can safely be ignored.

There can be various scenarios where you need to ignore some of the json properties while serializing/deserializing JSON like If you are consuming json from a web service and just want few meaningful fields to be serialized. For example from an employee details json, you want just the employee first name and last name. This way you will avoid having a heavy employee object.

If the consumed service upgrades in future adding some fields, your code will continue to work.

S.K.
  • 3,597
  • 2
  • 16
  • 31