3

I am trying to add the jackson annotation at the application level via application.yml file. But when I run the application, the jackson annotation is ignored and the response has the null attributes as well. Cn someone help me here? I have added the below line in my application.yml

spring.jackson: default-property-inclusion: NON_NULL

even after this I am seeing the response with null values.

Am I missing something or is there an issue with the version I m using? I am currently using jackson annotation version - 2.9.0

Anonymous
  • 47
  • 1
  • 7
  • Per documentation , the value is in lower case non_null – Gopi Feb 15 '19 at 15:40
  • Possible duplicate of [How to customise the Jackson JSON mapper implicitly used by Spring Boot?](https://stackoverflow.com/questions/28324352/how-to-customise-the-jackson-json-mapper-implicitly-used-by-spring-boot) – Michał Ziober Feb 15 '19 at 15:43
  • @Gopi property value is case insensitive. both non_null and NON_NULL works fine. – Ashish Lahoti Jun 14 '21 at 04:00

1 Answers1

1

Property spring.jackson.default-property-inclusion: NON_NULL works with latest spring-boot version 2.5.0.

For older versions, where the property doesn't work, you can use @JsonInclude(Include.NON_NULL) annotation at class or field level.

Please note that field level annotation overrides the class level annotation, and class level annotation overrides the application level property.

Ashish Lahoti
  • 648
  • 6
  • 8