深拷贝的最简单实现(使用fastjson)

内容分享1天前发布
0 0 0

示例

public static void main(String[] args) {
        List<StudentCard> mikeCards = new ArrayList<>();
        StudentCard mikeCard = new StudentCard();
        mikeCard.setId("001").setDescription("mike s card");
        mikeCards.add(mikeCard);

        Student mike = new Student();
        mike.setAge(12).setName("mike").setNum("00123").setStudentCardList(mikeCards);
        List<Student> studentList1 = new ArrayList<>();
        studentList1.add(mike);

        String studentList1String = JSON.toJSONString(studentList1);
        System.out.println(studentList1String);

        List<Student> studentList2 = JSONObject.parseArray(studentList1String,Student.class);
        System.out.println(studentList2.toString());

    }

利用fastJson的转换,不需要序列化,不需要手动赋值

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...