Fastjson and jackson are commonly used for Json parsing. There are a lot of comparisons on the performance of the Internet, saying that fastjson is better. Today we will sort out jackson's stuff and then send another fastjson one.
Jackson is a built-in json Conversion Tool of spring mvc, while fastjson is an open-source toolkit made by Alibaba.
Jackson serialization is as follows:
String jsonSerialize( ObjectMapper om = } }
Jackson deserialization is as follows:
Object jsonDeserialize( String json, Class<?> ObjectMapper om = } }
Json deserialization may occur during use. When your object contains get ** (), it is treated as an attribute, so when you serialize the json, during deserialization, it is very likely that an exception occurs, because this *** definition is not available in your model.
What should we do?
Jackson provides his own solution (JacksonHowToIgnoreUnknow ):
1. Add a declaration to ignore unknown attributes on the class: @ JsonIgnoreProperties (ignoreUnknown = true)
2. Add ignore unknown attribute parsing in deserialization, as shown below:
Object jsonDeserialize( String json, Class<?> ObjectMapper om = om.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, } }
3. Add "Any setter" to process unknown attributes
}
4. register the issue handling handle
Register a DeserializationProblemHandler handle to call ObjectMapper. addHandler (). When a handle is added, the handleUnknownProperty method of the handle can be called once on each unknown property.
This method is useful when you want to add an unknown attribute to process logs: When the attribute is uncertain, it will not cause a property binding error.