doRun(SerializerFactory.create(format, CompressionType.GZIP, true), 8, true);
}
private void doRun(Serializer serializer, int spaces, boolean newline) throws Exception {
//serializer.setPrettyPrint(true);
Car car = new Car(new Person("Dave"));
long start = System.currentTimeMillis();
byte[] bytes = serializer.serialize(car, Car.class);
//System.out.println(new String(bytes));
car = serializer.deserialize(bytes, Car.class);
long stop = System.currentTimeMillis();
boolean debug = false; // toggle this is you're interested in performance
if (debug) {
StringBuilder sb = new StringBuilder();
for (int i=0; i < spaces; i++) {
sb.append(' ');
}
sb.append(serializer.getClass().getSimpleName());
sb.append(": ");
sb.append(bytes.length);
sb.append(" bytes serialized and deserialized in ");
sb.append(stop - start);
sb.append(" milliseconds");
if (newline) {
sb.append("\n");
}
System.out.println(sb);
}
Assert.assertEquals("Dave", car.getDriver().getNickName());
}