Details
-
Type: Bug
-
Status: Closed
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: 1.x Maintenance
-
Component/s: None
-
Labels:None
-
JDK version and platform:Sun jdk1.2.2 - Websphere 4.0.7
Description
I'm using xtsream 1.1.2 with jdk 1.2. While converting from and to xml xstream changes the behaviour of Typesafe Enum. Eg if I have a Typesafe Enum class - MyEnum with 3 static variables as Enum1=1, Enum2=2 and Enum3=3. The value of Enum1 changes when the xstream serializes or deserializes the object. I have made sure there is no issue with Typesafe Enum ie readresolve and hashcode.
Hi Harmanjit,
since XStream does not support JDK 1.2.x I suppose you've using JDK 1.3. However, you're hit by a limitation of the PureJavaReflectionProvider, that is in action for JDK 1.3. This provider has to call the default ctor to recreate an instance. Unfortunately your class does not declare one (not even private), therefore it uses the JDK serialization as fallback to create a new instance that works under some circumstances. Now, since you've declared a readResolve method, it will already be called by this mechanism and (since the ordinalValue is always initialized 0) your method will return the first entry of your static list that is (each time) overwritten in consequence.
To solve the issue, you have to declare a default ctor or implement a SingleValueConverter, that might also produce a nicer XML.