// based on the example in the two-minute tutorial.
public class XStreamTest {
public static class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
public Person(String firstname, String lastname, PhoneNumber phone, PhoneNumber fax) {
this.firstname = firstname;
this.lastname = lastname;
this.phone = phone;
this.fax = fax;
}
}
public static class PhoneNumber {
private int code;
private String number;
public PhoneNumber(int code, String number) {
this.code = code;
this.number = number;
}
}
public static void main(String... args) {
XStream xstream = new XStream();
xstream.alias("person", Person.class);
xstream.alias("phonenumber", PhoneNumber.class);
Person joe = new Person("Joe", "Walnes", new PhoneNumber(123, "1234-456"), new PhoneNumber(123, "9999-999"));
final int warmup = 10000;
final int runs = 20000;
long start = 0;
for (int i = -warmup; i < runs; i++) {
if(i == 0) start = System.nanoTime();
String xml = xstream.toXML(joe);
}
long time = System.nanoTime() - start;
System.out.printf("Took %,d us on average to serialise a Person%n", time / runs / 1000);
}
}