ObjectMapper om = new ObjectMapper();
String result;
try {
result = om.writeValueAsString(cookBookDetail);
System.out.println(result);
} catch (JsonGenerationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JsonMappingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
转到其它类型也是可以的,敲入writevalue就能看到。
spring-android引入了这个库,使用起来非常方便,避免再引入gson库了
本文介绍如何利用Java中的ObjectMapper简化JSON数据的处理过程,包括将对象转换为JSON字符串等常见操作,并提及了spring-android项目的应用案例,指出其优势在于无需额外引入gson等依赖。
1371

被折叠的 条评论
为什么被折叠?



