Wednesday, January 23, 2013

XStream and Circular References

I recently came across a problem when marshalling a Java object to XML using XStream was creating circular references. XStream will detect and include absolute/relative paths to circular references, which can be cumbersome when the XML is to be parsed manually (as in my case). Luckily, there is a way to turn off such references and to print each object as a tree:

     XStream xstream = new XStream();  
     xstream.setMode(XStream.NO_REFERENCES);  

Reference:
http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/XStream.html