xstream:
XStream xstream = new XStream();
// XStream xstream = new XStream(new DOMDriver());//线程安全
xstream.alias("person", Person.class);
xstream.alias("phonenumber", PhoneNumber.class);
Person person = new Person("Chen", "Tao");
person.setPhone(new PhoneNumber(123, "1234-456"));
person.setFax(new PhoneNumber(123, "9999-999"));
//序列化
String xml = xstream.toXML(person);
System.out.println(xml);
//反序列化
XStream xstream2 = new XStream();
xstream2.alias("person", Person.class);
xstream2.alias("phonenumber", PhoneNumber.class);
xstream2.fromXML(xml);
// Person newPerson = (Person) xstream2.fromXML(xml);
用到的包:
xstream-1.4.1.jar
xpp3_min-1.1.4c.jar –用于反序列化
xmlpull-1.1.3.1.jar
ps:真他妈的慢啊
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net