SpringBoot returns responses that exclude fields that are null
Global configuration can be used to make the field in the returned response null
no longer appear in the returned result.
Note: This configuration makes the fields contained in the returned response change with the request result, and it is not intuitive which fields are contained in the response; configuration is not recommended unless there is a clear need for the business.
PS: When Gson converts beans to JSON, null fields are excluded by default.
configuration
# json 序列化,返回响应中排除值为 null 的字段
spring.jackson.default-property-inclusion=non-null
example
Before adding configuration:
After adding the configuration:
errorCode
and errorMessage
two fields, the result is no longer returned.
reference
https://blog.csdn.net/qingquanyingyue/article/details/119252258