Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-14631

Support custom type converters for Enums

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: came-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      It should be possible to provide a custom TypeConverter for converting strings into an Enum instances.

      The conversion of `String` to `Enum` is hard coded to fail with an Exception if `EnumTypeConverter` cannot instantiate an `Enum` constant by name. However, Java allows to override the string representation for enums. Converting such strings back to enums is only possible through a special converting function.

      Currently `org.apache.camel.impl.converter.EnumTypeConverter` tries to find the Enum instance by name. If that fails it falls backĀ  to calling the built-in valueOf(String) method which will end the program with a RuntimeException. The type conversion process stops there instead of further looking for custom type converters. The line with `return null;` in `EnumTypeConverter` is never reached. Would `EnumTypeConverter` indeed return null, the process would continue and a custom converter would finally be called.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              claussni Ralf Claussnitzer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: