Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 1.4.4
-
Fix Version/s: 1.4.5
-
Component/s: Converters
-
Labels:None
-
JDK version and platform:Sun 1.6
Description
See the following code snippet
Enum Symbology {RIC, ISIN}; @XStreamAlias("view") @XStreamConverter(value = ToAttributedValueConverter.class, strings ={"Underlying"}) public class UnderlyingView { @XStreamAsAttribute public Symbology symbology; public String Underlying; }
Whenever this class is converted to XML (irrespective of driver) the output is as follows <view>RICunderlying1</view>(with below simple groovy snippet):
XStream xStream = new XStream() UnderlyingView un = new UnderlyingView([symbology: "RIC", Underlying: "underlying1"]) println xStream.toXML(un)
The text content is all fine, however the attribute, which is an enum is lost, and merged into the text node. It is also possible to deserialize a properly formatted XML {{<view symbology="RIC">Underlying1</view>}}into this view.
From looking at the code for ToAttributedValueConverter it only works properly if the converter in use is a SingleValueConverter. However XStream is using EnumConverter for the enum, and not EnumSingleValueConverter.
As said on the mailing list, XStream ha a special handling for enums that have to be written as attributes. Unfortunately this mechanism failed for this converter, since the converter allows explicitly that all fields are written as attributes without any additional declaration. However, fixed in trunk.