[Simple-support] BigInteger in CycleStrategy problem
Brought to you by:
niallg
|
From: Joselito D. M. <joe...@gm...> - 2009-02-17 17:41:47
|
Hello,
Is there a way to turn off CycleStrategy for Elements that are standard java
types?
Let me explain.
Given the class definition:
@Root
public class AClass {
@Element
private BigInteger aBigInteger;
@Element
private BigInteger anotherBigInteger;
//(Setters, getters implied for this code)
}
//In the test code
public class SomeTest {
@Test
public class aTest() {
BigInteger aBigInteger = new BigInteger("0");
AClass aClass = new AClass();
aClass.setABigInteger(aBigInteger);
aClass.setAnotherBigInteger(aBigInteger);
Strategy strategy = new CycleStrategy();
Serializer serializer = new Persister(strategy);
StringWriter writer = new StringWriter();
serializer.write(aClass, writer);
System.out.println(writer.toString());
}
}
The output is:
<AClass id="0">
<aBigInteger id="1">0</aBigInteger>
<anotherBigInteger reference="1"/>
</AClass>
What I need is:
<AClass id="0">
<aBigInteger id="1">0</aBigInteger>
<anotherBigInteger id="2">0</anotherBigInteger>
</AClass>
That is, I need the second BigInteger property to be treated not as an
element reference because I want standard java data types in my beans to be
treated as different instances even though at runtime, they are pointing to
the same instance.
Could this be added as a future feature maybe?
Thanks,
Joen Moreno
|