Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java serialization testing

Does anyone know if there is a library that exists to help test if an object graph is fully serializable? It would probably be as simple as writing it out and reading it back in, but I figured someone must have abstracted this already - I just can't find it.

like image 356
Jeff Storey Avatar asked Nov 23 '25 00:11

Jeff Storey


1 Answers

Read this article.

and note the following highly re-usable function :

public void testIsSerializable() 
   throws JaxenException, IOException {

    BaseXPath path = new BaseXPath("//foo", new DocumentNavigator());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(path);
    oos.close();
    assertTrue(out.toByteArray().length > 0);

}

The article also explains how to test whether the objects were correctly serialized.

like image 93
Amir Afghani Avatar answered Nov 25 '25 15:11

Amir Afghani