Search code examples
javaparsingserializationxstream

Xstream inserts strange tags in output


I have an XML Processing Application ( coded in java) that is supposed to take 2 reports of JavaNcss tool and compile their diff.

The sample XML is as follows :

<objects>
<object>
<name>Object Name</name>
<ncss>8</ncss>
<functions>2</functions>
<classes>0</classes>
<javadocs>2</javadocs>
</object>
</objects>

While the application itself is working accurately , I noticed the inclusion of the following tags in the output :

    <object reference="../object[18]"/>
    <object reference="../object[41]"/>
    <object reference="../object[10]"/>
    <object reference="../object[41]"/>
    <object reference="../object[12]"/>
    <object reference="../object[41]"/>
    <object reference="../object[14]"/>

I have no clue as to what is causing this trouble. Any help would be greatly appreciated. Thanks in advance.


Solution

  • XStream explanation here http://x-stream.github.io/graphs.html.

    If it finds duplicate object then it uses the reference to refer to the earlier one. This is the default behavior.

    If you do not want then do this xstream.setMode(XStream.NO_REFERENCES);