Class EnumConverter

java.lang.Object
org.apache.commons.beanutils.converters.AbstractConverter
dev.orne.beans.converters.EnumConverter
All Implemented Interfaces:
org.apache.commons.beanutils.Converter

@API(status=STABLE, since="0.1") public class EnumConverter extends org.apache.commons.beanutils.converters.AbstractConverter
Implementation of Converter that converts Enum instances to and from String using value name as String representation.
Since:
0.1
Version:
2.1, 2022-10
Author:
(w) Iker Hernaez
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final EnumConverter
    Shared instance that throws a ConversionException if an error occurs.
    static final EnumConverter
    Shared instance that returns null if an error occurs.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    protected <T> T
    convertToType(@NotNull Class<T> type, Object value)
    protected <T> T
    enumFromName(@NotNull Class<T> type, @NotNull String name)
    Returns the enumeration constant of the specified type that matches the specified enumeration name.
    protected @NotNull Class<?>
    static void
    Registers EnumConverter.GENERIC for the Enum class in the singleton Apache commons bean utils converter.
    static void
    register(org.apache.commons.beanutils.ConvertUtilsBean converter)
    Registers EnumConverter.GENERIC for the Enum class in the specified Apache commons bean utils converter.
    static void
    Registers EnumConverter.GENERIC_DEFAULT for the Enum class in the singleton Apache commons bean utils converter.
    static void
    registerWithDefault(org.apache.commons.beanutils.ConvertUtilsBean converter)
    Registers EnumConverter.GENERIC_DEFAULT for the Enum class in the specified Apache commons bean utils converter.

    Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter

    conversionException, convert, convertArray, getDefault, handleError, handleMissing, isUseDefault, setDefaultValue, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • GENERIC

      public static final EnumConverter GENERIC
      Shared instance that throws a ConversionException if an error occurs.
    • GENERIC_DEFAULT

      public static final EnumConverter GENERIC_DEFAULT
      Shared instance that returns null if an error occurs.
  • Method Details

    • getDefaultType

      @NotNull protected @NotNull Class<?> getDefaultType()
      Specified by:
      getDefaultType in class org.apache.commons.beanutils.converters.AbstractConverter
    • convertToType

      protected <T> T convertToType(@NotNull @NotNull Class<T> type, Object value) throws Throwable
      Specified by:
      convertToType in class org.apache.commons.beanutils.converters.AbstractConverter
      Throws:
      Throwable
    • enumFromName

      protected <T> T enumFromName(@NotNull @NotNull Class<T> type, @NotNull @NotNull String name)
      Returns the enumeration constant of the specified type that matches the specified enumeration name.
      Type Parameters:
      T - The enumeration type
      Parameters:
      type - The enumeration type
      name - The name of the constant
      Returns:
      The enumeration constant for the name
      Throws:
      org.apache.commons.beanutils.ConversionException - If the type is not an enumeration or no constant matches the specified name
    • convertToString

      protected String convertToString(Object value) throws Throwable
      Overrides:
      convertToString in class org.apache.commons.beanutils.converters.AbstractConverter
      Throws:
      Throwable
    • register

      public static void register()
      Registers EnumConverter.GENERIC for the Enum class in the singleton Apache commons bean utils converter.

      Note that the default ConvertUtilsBean implementation doesn't fallback to Enum when converting enumerations. Instances of EnumConvertUtilsBean or EnumConvertUtilsBean2 must be used to this converter apply.

    • register

      public static void register(org.apache.commons.beanutils.ConvertUtilsBean converter)
      Registers EnumConverter.GENERIC for the Enum class in the specified Apache commons bean utils converter.

      Note that the default ConvertUtilsBean implementation doesn't fallback to Enum when converting enumerations. Instances of EnumConvertUtilsBean or EnumConvertUtilsBean2 must be used to this converter apply.

      Parameters:
      converter - The Apache commons bean utils converter to register to
    • registerWithDefault

      public static void registerWithDefault()
      Registers EnumConverter.GENERIC_DEFAULT for the Enum class in the singleton Apache commons bean utils converter.

      Note that the default ConvertUtilsBean implementation doesn't fallback to Enum when converting enumerations. Instances of EnumConvertUtilsBean or EnumConvertUtilsBean2 must be used to this converter apply.

    • registerWithDefault

      public static void registerWithDefault(org.apache.commons.beanutils.ConvertUtilsBean converter)
      Registers EnumConverter.GENERIC_DEFAULT for the Enum class in the specified Apache commons bean utils converter.

      Note that the default ConvertUtilsBean implementation doesn't fallback to Enum when converting enumerations. Instances of EnumConvertUtilsBean or EnumConvertUtilsBean2 must be used to this converter apply.

      Parameters:
      converter - The Apache commons bean utils converter to register to