zoukankan      html  css  js  c++  java
  • com.fasterxml.jackson.databind.ObjectMapper. .readValue .convertValue

        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);
  • 相关阅读:
    Picture
    wolf and rabbit
    十进制转换为二进制(一直不会算的)
    各种排序
    折线分割平面
    字母数
    1001
    Primes
    大数的减法神秘数
    转: Windows Internet WinINet 学习笔记(2)
  • 原文地址:https://www.cnblogs.com/hahajava/p/9354116.html
Copyright © 2011-2022 走看看