Details
Description
Code below:
import com.thoughtworks.xstream.*;
class MultRef
{
public Object s1 = new Object();
public Object s2 = s1;
}
public class Test2
{
public static void main(String[] args)
{ MultRef multRef1 = new MultRef(); if (multRef1.s1 == multRef1.s2) System.out.println("multRef1: References"); else System.out.println("multRef1: NOT References"); XStream xstream = new XStream(); String xml = xstream.toXML(multRef1); System.out.println(xml); MultRef multRef2 = (MultRef)xstream.fromXML(xml); if (multRef2.s1 == multRef2.s2) System.out.println("multRef2: References"); else System.out.println("multRef2: NOT References"); }}
Currently produces:
multRef1: References
<MultRef>
<s1/>
<s2 reference="../s1"/>
</MultRef>
multRef2: NOT References // WRONG!
Reported by Jim Gentilesco.
This patch should fix the problem. The idea is that we need to put a reference to every object into the map since we don't know which ones will have references to them later on in the file.