Spring REST Service: how to configure to remove null objects in json response Spring REST Service: how to configure to remove null objects in json response spring spring

Spring REST Service: how to configure to remove null objects in json response


Since Jackson 2.0 you can use JsonInclude

@JsonInclude(Include.NON_NULL)public class Shop {    //...}


Since Jackson is being used, you have to configure that as a Jackson property. In the case of Spring Boot REST services, you have to configure it in application.properties or application.yml:

spring.jackson.default-property-inclusion = NON_NULL

source


@JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY)public class Shop {    //...}

for jackson 2.0 or later use @JsonInclude(Include.NON_NULL)

This will remove both empty and null Objects.