1

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?

dmj
  • 21
  • 5
  • Try using the jackson library and annotate your class with `@JsonInclude(Include.NON_NULL)` – k9yosh May 04 '21 at 09:02
  • Does this answer your question? [Spring REST Service: how to configure to remove null objects in json response](https://stackoverflow.com/questions/12707165/spring-rest-service-how-to-configure-to-remove-null-objects-in-json-response) – Marc Tarin May 05 '21 at 06:57

1 Answers1

1

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)
Tamil.S
  • 403
  • 3
  • 14