1.空值转换:
Can not instantiate value of type [map type; class java.util.HashMap, [simple type, class java.lang.String] -> [simple type, class java.lang.String]] from JSON String; no single-String constructor/factory method
解决方法,在ObjectMapper配置中增加:
mapper.configure(DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) ;
2.转义字符-异常情况
org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 0)): has to be escaped using backslash to be included in string value
at [Source: java.io.StringReader@10cfc2e3; line: 1, column: 2461]
解决办法,在ObjectMapper配置中增加:
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true) ;
3.当反序列化的json对象中有某些字段,但mapper对象中没有该字段时报错。
解决办法,增加mapper的属性配置
objectMapper .configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false)
4.无法反序列化没有START_OBJECT token的ArrayList
解决办法:增加mapper的属性配置:
objectMapper.configure(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
5.unrecognized character escape 值里面有\
解决办法:增加mapper的属性配置:
objectMapper.configure(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,true);