Swagger codegen ignore null fields for POJO classes

Viewed 6838

I'm making a REST API and I would like to add at the class generation the Jackson annotation to ignore null fields, so I would like to add this annotation onfly for certain classes, not for the hole project.

I know that this could be acomplished by adding in application.properties the following line :

spring.jackson.default-property-inclusion=non_null

But this is for entire project.

I see that there are some ".mustache" files

- api.mustache
- apiController.mustache

I supose that I have to add some code in one of this one, or should I insert some code in application.yml ?

I'm also using Spring Boot with Swagger-codgen.

Thank you in advance and have a nice day!

2 Answers

You can try to set below proprty in application.yaml

spring.jackson.default-property-inclusion = NON_NULL

This worked for me to filter out null values from response.

Related