SpringBoot returns responses that exclude fields that are null

SpringBoot returns responses that exclude fields that are null

Global configuration can be used to make the field in the returned response nullno 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:
insert image description here

After adding the configuration:
errorCodeand errorMessagetwo fields, the result is no longer returned.
insert image description here

reference

https://blog.csdn.net/qingquanyingyue/article/details/119252258

Guess you like

Origin blog.csdn.net/sgx1825192/article/details/132460685