public static void main(String[] args) {
//java bean 转 xml
Dept d = new Dept();
List staffs = new ArrayList<>();
Staff s1 = new Staff("wuyun", 20);
Staff s2 = new Staff("lilei", 22);
staffs.add(s1);
staffs.add(s2);
d.setDeptName("开放平台");
d.setStaffs(staffs);
System.out.println(objectToXml(d));
/*
用这个方法 XStream xStream = new XStream(); 会有下划线问题
开放平台
wuyun
20
lilei
22
XStream xStream = new XStream(new XppDriver(new XmlFriendlyNameCoder("_-", "_")));//可以解决下划线问题
开放平台
wuyun
20
lilei
22
*/
//xml 转 java bean//String xml = "开放平台wuyun20lilei22";//XStream xstream = new XStream(new DomDriver());// //xstream使用注解转换//xstream.processAnnotations(Dept.class);//System.out.println(((Dept) xstream.fromXML(xml)).toString());//System.out.println(xmlToObject(xml, Dept.class).toString());
/*
com.cmcc.open.ss.vo.req.Dept@5660d2d2[
deptName=开放平台
staffs=[com.cmcc.open.ss.vo.req.Staff@6eb1054b[
name=wuyun
age=20
], com.cmcc.open.ss.vo.req.Staff@27d2b7b3[
name=lilei
age=22
]]
]
*/
}