Created
March 9, 2012 10:00
-
-
Save jeremie-lesage/2005911 to your computer and use it in GitHub Desktop.
Xstream in two minute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** http://xstream.codehaus.org/tutorial.html **/ | |
public class DemoXstreal { | |
public class Person { | |
private String firstname; | |
private String lastname; | |
private PhoneNumber phone; | |
private PhoneNumber fax; | |
// ... constructors and methods | |
} | |
public class PhoneNumber { | |
private int code; | |
private String number; | |
// ... constructors and methods | |
} | |
public static void main(String[] args) { | |
XStream xstream = new XStream(new StaxDriver()); | |
// Serializing an object to XML | |
Person joe = new Person("Joe", "Walnes"); | |
joe.setPhone(new PhoneNumber(123, "1234-456")); | |
joe.setFax(new PhoneNumber(123, "9999-999")); | |
String xml = xstream.toXML(joe); | |
//Deserializing an object back from XML | |
Person newJoe = (Person)xstream.fromXML(xml); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment