Skip to content

Instantly share code, notes, and snippets.

@sureshnath
Last active December 16, 2015 06:58
Show Gist options
  • Save sureshnath/5394860 to your computer and use it in GitHub Desktop.
Save sureshnath/5394860 to your computer and use it in GitHub Desktop.
test simple xml serialisation
public static <T> T testSerialisation(Class<? extends T> type, T expected) {
Serializer serializer = new Persister();
StringWriter sw = new StringWriter();
T actual = null;
try {
serializer.write(expected, sw);
} catch (Exception ex) {
LOG.error("testing serialisation failed", ex);
Assert.fail("testing serialisation failed");
}
LOG.debug(sw.toString());
try {
actual = serializer.read(type, sw.toString());
} catch (Exception ex) {
LOG.error("testing de-serialisation failed", ex);
Assert.fail("testing de-serialisation failed");
}
Assert.assertNotNull("de-serialised to null object", actual);
Assert.assertEquals("de-serialisation equals failed", expected, actual);
return actual;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment