dmj
dmj

Reputation: 61

Exclude null properties from Spring Boot Rest controllers

I have a rest service exposed using spring boot rest controller but with the response i'm sending object's properties those has null values.

For ex : ReponseEntity.ok(list) and that list consist of Objects A with lot of null properties.

Is there an easy way of excluding those null properties with spring boot tools?

Upvotes: 3

Views: 2921

Answers (1)

Tamil.S
Tamil.S

Reputation: 483

You can try this in application.properties file

spring.jackson.default-property-inclusion=non_null

Ref - https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper

or you can try following annotation in class level or property level

@JsonInclude(JsonInclude.Include.NON_NULL)

Upvotes: 4

Related Questions