If the jackson object to json is NULL or empty, serialization is not performed.
1. Entity
@ JsonInclude (Include. NON_NULL)
// Place the tag on the property. If the property is NULL, it is not involved in serialization.
// If it is placed on the top of the class, it takes effect for all the attributes of the class.
// Include. Include. ALWAYS default
// Include. NON_DEFAULT attribute is default value not serialized
// Include. NON_EMPTY property is NULL ("") or NULL is not serialized
// Include. NON_NULL attribute is NULL and is not serialized
2. Code
ObjectMapper mapper = new ObjectMapper ();
Mapper. setserializationsion Sion (Include. NON_NULL );
// Set the mapper object using this method. All serialized objects are serialized according to the modified rules.
// Include. Include. ALWAYS default
// Include. NON_DEFAULT attribute is default value not serialized
// Include. NON_EMPTY property is NULL ("") or NULL is not serialized
// Include. NON_NULL attribute is NULL and is not serialized
User user = new User (1, "", null );
String outJson = mapper. writeValueAsString (user );
System. out. println (outJson );
Jackson object to json attributes directly does not participate in serialization
---------------------------------------------
@ JsonIgnore
Private int id;