使用com.fasterxml.jackson将对象转换为JSON字符串或反转

2018-01-13 11:15:31来源:oschina作者:源哥L人点击

分享
示例: import com.fasterxml.jackson.databind.ObjectMapper;Iterable areaItera = areaRepository.findAll();

StringWriter writer = new StringWriter();
ObjectMapper mapper = new ObjectMapper();
try {
mapper.writeValue(writer, areaItera);
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("areaString:"+writer.toString());
Map> blockMap = mapper.readValue(writer.toString(), Map.class);
System.out.println(blockMap.toString());

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台