Class EnumConverter
- All Implemented Interfaces:
org.apache.commons.beanutils.Converter
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
Modifier and TypeFieldDescriptionstatic final EnumConverter
Shared instance that throws aConversionException
if an error occurs.static final EnumConverter
Shared instance that returnsnull
if an error occurs. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
convertToString
(Object value) 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
register()
RegistersEnumConverter.GENERIC
for theEnum
class in the singleton Apache commons bean utils converter.static void
register
(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC
for theEnum
class in the specified Apache commons bean utils converter.static void
RegistersEnumConverter.GENERIC_DEFAULT
for theEnum
class in the singleton Apache commons bean utils converter.static void
registerWithDefault
(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC_DEFAULT
for theEnum
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
-
Field Details
-
GENERIC
Shared instance that throws aConversionException
if an error occurs. -
GENERIC_DEFAULT
Shared instance that returnsnull
if an error occurs.
-
-
Method Details
-
getDefaultType
- Specified by:
getDefaultType
in classorg.apache.commons.beanutils.converters.AbstractConverter
-
convertToType
- Specified by:
convertToType
in classorg.apache.commons.beanutils.converters.AbstractConverter
- Throws:
Throwable
-
enumFromName
Returns the enumeration constant of the specified type that matches the specified enumeration name.- Type Parameters:
T
- The enumeration type- Parameters:
type
- The enumeration typename
- 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
- Overrides:
convertToString
in classorg.apache.commons.beanutils.converters.AbstractConverter
- Throws:
Throwable
-
register
public static void register()RegistersEnumConverter.GENERIC
for theEnum
class in the singleton Apache commons bean utils converter.Note that the default
ConvertUtilsBean
implementation doesn't fallback toEnum
when converting enumerations. Instances ofEnumConvertUtilsBean
orEnumConvertUtilsBean2
must be used to this converter apply. -
register
public static void register(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC
for theEnum
class in the specified Apache commons bean utils converter.Note that the default
ConvertUtilsBean
implementation doesn't fallback toEnum
when converting enumerations. Instances ofEnumConvertUtilsBean
orEnumConvertUtilsBean2
must be used to this converter apply.- Parameters:
converter
- The Apache commons bean utils converter to register to
-
registerWithDefault
public static void registerWithDefault()RegistersEnumConverter.GENERIC_DEFAULT
for theEnum
class in the singleton Apache commons bean utils converter.Note that the default
ConvertUtilsBean
implementation doesn't fallback toEnum
when converting enumerations. Instances ofEnumConvertUtilsBean
orEnumConvertUtilsBean2
must be used to this converter apply. -
registerWithDefault
public static void registerWithDefault(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC_DEFAULT
for theEnum
class in the specified Apache commons bean utils converter.Note that the default
ConvertUtilsBean
implementation doesn't fallback toEnum
when converting enumerations. Instances ofEnumConvertUtilsBean
orEnumConvertUtilsBean2
must be used to this converter apply.- Parameters:
converter
- The Apache commons bean utils converter to register to
-