开发者

Java serialization testing

开发者 https://www.devze.com 2022-12-29 18:53 出处:网络
Does anyone know if there is a library that exists to help test if an object graph is fully serializable? It would prob开发者_Python百科ably be as simple as writing it out and reading it back in, but

Does anyone know if there is a library that exists to help test if an object graph is fully serializable? It would prob开发者_Python百科ably 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消