实体类:
@XStreamAlias
(
"person"
)
public
class
PersonBean {
@XStreamAlias
(
"firstName"
)
private
String firstName;
@XStreamAlias
(
"lastName"
)
private
String lastName;
@XStreamAlias
(
"telphone"
)
private
PhoneNumber tel;
@XStreamAlias
(
"faxphone"
)
private
PhoneNumber fax;
//测试一个标签下有多个同名标签
@XStreamAlias
(
"friends"
)
private
Friends friend;
//测试一个标签下循环对象
@XStreamAlias
(
"pets"
)
private
Pets pet;
//省略setter和getter
}
public class XMLUtils {
public static String toXml(Object obj){
XStream xstream=new XStream();
xstream.processAnnotations(obj.getClass());
return xstream.toXML(obj);
}
}
利用Xstream注解生成和解析xml,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/yanfly/p/3851149.html