一个简单的基于Java库,Java对象序列化到XML XStream

作者: cayman 分类: 编程技术 发布时间: 2020-07-29 15:19
<dependency>
    <groupId>com.thoughtworks.xstream</groupId>
    <artifactId>xstream</artifactId>
    <version>1.4.11.1</version>
</dependency>

1、序列化对象到XML

XStream xstream = new XStream(new StaxDriver());
String xml = xstream.toXML(student);

2、 反序列化XML获得对象

XStream xstream = new XStream(new StaxDriver());
Student student1 = (Student) xstream.fromXML(xml);

发表评论

电子邮件地址不会被公开。 必填项已用*标注