java写的一个对像xml序列化解析的demo

本文介绍如何使用XStream库将Java对象序列化为XML格式,并演示了一个具体示例,包括创建对象、序列化过程及反序列化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载附件中的xstream-1.1.3.jar包
2.建立一个文件Integral.java代码如下:
public class Integral {
private int caseId;
private Date surveyCompleteTime;

public int getCaseId() {
return caseId;
}

public void setCaseId(int caseId) {
this.caseId = caseId;
}

public Date getSurveyCompleteTime() {
return surveyCompleteTime;
}

public void setSurveyCompleteTime(Date surveyCompleteTime) {
this.surveyCompleteTime = surveyCompleteTime;
}

public static void main(String[] args) {
XStream xstream = new XStream(new DomDriver());
xstream.alias("Integral", Integral.class);
Integral i = new Integral();
i.setSurveyCompleteTime(Calendar.getInstance().getTime());
i.setCaseId(120);
String xml = xstream.toXML(i);
System.out.println(xml);
Integral i2 = (Integral) xstream.fromXML(xml);
System.out.println(i2.getCaseId() + "|" + i2.getSurveyCompleteTime());
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值