本文主要是介绍使用ObjectMapper对java对象和Map进行json格式转换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
依赖包
1.jackson-core-asl-1.9.13.jar
2.jackson-mapper-asl-1.9.13.jar
public class Test {public static void main(String[] args) throws Exception{ObjectMapper o = new ObjectMapper();Student std = new Student("张三",20);String out1 = o.writeValueAsString(std);System.out.println(out1);Map<String,Integer> map = new HashMap<String,Integer>();map.put("李四", 30);map.put("王五", 40);String out2 = o.writeValueAsString(map);System.out.println(out2);}
}
{"name":"张三","age":20}
{"李四":30,"王五":40}
这篇关于使用ObjectMapper对java对象和Map进行json格式转换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!