import com.thoughtworks.xstream.XStream;
public class XStreamExample {
public static void main(String[] args) {
XStream xstream = new XStream();
xstream.alias("person", Person.class);
xstream.alias("address", Address.class);
Person person = new Person("John Doe", 30);
person.setAddress(new Address("123 Street", "City", "Country"));
String xml = xstream.toXML(person);
System.out.println(xml);
Person restoredPerson = (Person)xstream.fromXML(xml);
}
}
public class Person {
private String name;
private int age;
private Address address;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public class Address {
private String street;
private String city;
private String country;
public Address(String street, String city, String country) {
this.street = street;
this.city = city;
this.country = country;
}
}