码迷,mamicode.com
首页 > 移动开发 > 详细

com.fasterxml.jackson.databind.ObjectMapper. .readValue .convertValue

时间:2018-07-23 15:05:24      阅读:787      评论:0      收藏:0      [点我收藏+]

标签:tag   array   gets   sys   stack   bind   get   com   except   

 

    String str="{\"student\":[{\"name\":\"leilei\",\"age\":23},{\"name\":\"leilei02\",\"age\":23}]}";
    Student stu = null;
    List<Student> list = null;
    try {
        ObjectMapper objectMapper=new ObjectMapper();
        StudentList studentList=objectMapper.readValue(str, StudentList.class);
        list=studentList.getStudent();
    } catch (Exception e) {
        e.printStackTrace();
    } 
    list.streams.forEach(System::out::println)

 

ArrayList<Student> list=new ArrayList<Student>();
Student s1=new Student(); s1.setName("leilei01"); s1.setAge(23);
Student s2=new Student(); s2.setName("leilei02"); s2.setAge(23);
list.add(s1); list.add(s2);
StringWriter str=new StringWriter();
ObjectMapper objectMapper=new ObjectMapper();
try {
    objectMapper.writeValue(str, list);
} catch (Exception e) {
    e.printStackTrace();
}   
System.out.println(str);

 

com.fasterxml.jackson.databind.ObjectMapper. .readValue .convertValue

标签:tag   array   gets   sys   stack   bind   get   com   except   

原文地址:https://www.cnblogs.com/hahajava/p/9354116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!