There are two main ways:
-
Add annotations on the return of class:
@JsonInclude(JsonInclude.Include.NON_NULL)
This annotation can be null attributes in the entity class automatically ignored. -
Springboot project can modify the configuration file application.yml Global Auto ignored:
spring:
jackson:
default-property-inclusion: NON_NULL
- Other methods such as via Gson tools or methods, in the form of annotated on the interface, is similar concept.