Details
-
Type: New Feature
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.2.2
-
Component/s: None
-
Labels:None
Description
See user mailing list "HashCode corrupted on deserialzing map"
Currently Xstream always serializes subclasses before superclasses. For example:
public class Person {
public String name; //getters and setters
}
public class Employee extends Person {
public String address; //getters and setters
}
becomes serialized as:
<Employee>
<address>street 15</street>
<name>John Smith</name>
</Employee>
Besides the unlogical aesthetic aspect, this corrupts maps in subclasses that use keys based on superclassses (see user list).
The solution would be a boolean configuration property that enabled/disables superclass serializing before subclass serializing.
I would even propose to make enable it by default and provide disabling for backwards compability...
Java serialization always serializing superclasses before subclasses:
http://www.oreilly.com/catalog/javarmi/chapter/ch10.html
"An important part of serialization involves writing out class-related metadata associated with an instance. Most instances are more than one class. For example, an instance of String is also an instance of Object. Any given instance, however, is an instance of only a few classes. These classes can be written as a sequence: C1, C2...CN, in which C1 is a superclass of C2, C2 is a superclass of C3, and so on. This is actually a linear sequence because Java is a single inheritance language for classes. We call C1 the least superclass and CN the most-derived class."