XStream
  1. XStream
  2. XSTR-591

SingleValueEnumConverter uses toString() instead of name() for the value

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4
    • Component/s: Converters
    • Labels:
      None
    • JDK version and platform:
      1.6 apple 32bits

      Description

      All my enums have a localized toString() so they are used in comboboxes without change.
      in the xstream file they are saved with their toString, wich is good so my file doesn't speak too much the developer language (engrish), but more the user one (german).
      But the system is unable to unmarshall the enums because it is trying to use Enum.valeOf(type, string).
      This is sensible, but in my case, I want to use :
      try

      { //noinspection unchecked,RawUseOfParameterizedType return Enum.valueOf((Class) type, value); }

      catch (IllegalArgumentException e) {
      final Object[] enumConstants = type.getEnumConstants();
      for (final Object constant : enumConstants)

      { if (constant.toString().equals(value)) return constant; }

      throw e;
      }

      If I naively try to register a converter with XStream.registerConverter(SingleValueConverter) it is not taken into account because the internal EnumMapper takes precedence. And I don't want to register one converter by enum, they are all based on the same template in this part of my application.

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Nicolas Raynaud
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: