I'm using swagger-codgen to generate java model classes for my spring boot application and serialize them as json. By default these models would all include optional properties with null values.
I would like to configure the swagger-codgen for spring to include this annotation on top of all classes: @JsonInclude(Include.NON_NULL)
so that null valued properties are not included in the serialized json.
How can i achieve this? Is there a configuration option or do i have to extend the spring codegen manually?
You can configure that in your application.yaml
:
spring:
jackson:
default-property-inclusion: NON_NULL
One way of achieving that would be modifying the pojo template for Java Spring by adding the annotation. This template is used to generate the models.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With