History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-315
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Assignee: Unassigned
Reporter: Harmanjit
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

Error handling TypeSafe Enum

Created: 08/May/06 10:43 AM   Updated: 24/May/07 12:33 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.x Maintenance

File Attachments: 1. Java Source File MyEnum.java (3 kb)


JDK version and platform: Sun jdk1.2.2 - Websphere 4.0.7


 Description  « Hide
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.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 07/May/07 06:35 PM
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.

  • Jörg