}
private void assertBinarySerialization(Object root) {
// Serialize as binary
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xstream.marshal(root, new BinaryStreamWriter(outputStream));
// Deserialize the binary and check it equals the original object.
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
Object binaryResult = xstream.unmarshal(new BinaryStreamReader(inputStream));
assertObjectsEqual(root, binaryResult);