XStream
  1. XStream
  2. XSTR-741

Enum attribute combined with text content output incorrect

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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.

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Tamas Farago
        • Votes:
          0 Vote for this issue
          Watchers:
          2 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: