Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      1.5+

      Description

      Serialization of Java 5 Enum to/from xml attribute doesn't work:
      xstream.useAttributeFor(MyEnum.class)

      unless SingleValueConverter is registered:
      xstream.registerConverter(EnumSingleValueConverter.create(MyEnum.class));

      below (and in attachment) is the converter code:

      public class EnumSingleValueConverter<T extends Enum<T>>
      extends EnumConverter implements SingleValueConverter {

      private Class<T> enumType;

      public static <V extends Enum<V>> SingleValueConverter create(Class<V> enumClass)

      { return new EnumSingleValueConverter<V>(enumClass); }

      private EnumSingleValueConverter(Class<T> newEnumType)

      { this.enumType = newEnumType; }

      public boolean canConvert(Class type)

      { return type == enumType; }

      public Object fromString(String str)

      { return Enum.valueOf(enumType, str); }

      public String toString(Object obj)

      { return obj.toString(); }

      }

      it should be possible to add support for that in XStream facade so user wouldn't have to register anything.

        Issue Links

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            Piotr Metel
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: