0

So, I have a json object which I need to de-serialize to a POJO, make some changes to its fields then send that POJO through a controller to the front end. The json that I receive as a response to that controller has a lot of fields that are null as they did not exist in the json that was deserialized. I want the jackson library to not include any fields that have a null value.

The challenge I am facing is that I cannot add that @JsonInclude annotation to the Object class that I am trying to deserialize as the model class has been imported from a library and therefore the file is a readonly file. Is there a different way of configuring the default jackson settings for the project to not include these null values? Is there a default object mapper that can be configured?

  • See these questions: [How globally ignore Null Fields with restesy response?](https://stackoverflow.com/questions/54926701/how-globally-ignore-null-fields-with-restesy-response/54926911#54926911), [Jackson serialize null or empty object](https://stackoverflow.com/questions/57921579/jackson-serialize-null-or-empty-object/57921867#57921867) – Michał Ziober May 16 '23 at 14:37

1 Answers1

0

You can configure the mapper like this:

mapper.setSerializationInclusion(Include.NON_NULL);
Mar-Z
  • 2,660
  • 2
  • 4
  • 16