3

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I just figured someone had already packaged it up into a single method call.
The length test is pointless. It cannot possibly fail. An object stream has a header, defined by the protocol.
1

It would probably be as simple as writing it out and reading it back in

It's even simpler. Just write it out. If that succeeded, everything is serializable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.