- 序列化
-
ObjectMapper mapper = new ObjectMapper();//可以单例,线程安全 Object result=new Object(); mapper.writeValue(response.getWriter(), result);
-
- 反序列化
-
ObjectMapper mapper = new ObjectMapper(); Module m=mapper.readValue("{text: \"查询统计\" }", Module.class); System.out.println(m);
-
- 出现 org.codehaus.jackson.JsonParseException: Unexpected character 异常
- 属性名称没有用""括起来 ,需要加上配置 mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);(org.codehaus.jackson.JsonParseException: Unexpected character (')
- 如果属性名是用''括起来就要加上 mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
(org.codehaus.jackson.JsonParseException: Unexpected character (''' ) - 如果抛出org.codehaus.jackson.map.exc.UnrecognizedPropertyException:错误,
那么需要....配置.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES , false);