|
|
|
[
Permlink
| « Hide
]
Joerg Schaible - 12/Jun/07 10:56 AM
Since XStream 1.2.2 you can set the order in which the fields are saved (see FAQ). Starting with 1.3 the inherited fields will be saved first (see announcement of 1.2.2 release).
This modified case fails regardless of field order:
import java.util.Set; import java.util.TreeSet; import junit.framework.TestCase; import com.thoughtworks.xstream.XStream; public class Test extends TestCase { XStream xs = new XStream(); public void test() { C c = new C(1); c.others.add(c); c.others.add(new C(1)); /* same id */ xs.fromXML(xs.toXML(c)); } } class C implements Comparable { final Integer id; final Set<C> others = new TreeSet<C>(); C(Integer id) { this.id = id; } public int compareTo(Object o) { C c = (C) o; int cmp = id.compareTo(c.id); if (cmp != 0) { return cmp; } else { return new Integer(others.size()).compareTo(c.others.size()); } } } You're right, your second case also failed with the head revision. I've tested the same case with JDK serialization and had to recognize that they succeed. Main reason was, that the JDK contains an optimized functionality when a presorted set is added into an empty TreeSet. I changed the implementation of the TreeSetConverter (and TreeMapConverter) to behave the same. You may give the latest head revision a try.
|
|||||||||||||||||||||||||||||||||||||||||