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
FieldsModifier and TypeFieldDescriptionstatic final EnumConverterShared instance that throws aConversionExceptionif an error occurs.static final EnumConverterShared instance that returnsnullif an error occurs. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertToString(Object value) protected <T> TconvertToType(@NotNull Class<T> type, Object value) protected <T> TenumFromName(@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 voidregister()RegistersEnumConverter.GENERICfor theEnumclass in the singleton Apache commons bean utils converter.static voidregister(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERICfor theEnumclass in the specified Apache commons bean utils converter.static voidRegistersEnumConverter.GENERIC_DEFAULTfor theEnumclass in the singleton Apache commons bean utils converter.static voidregisterWithDefault(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC_DEFAULTfor theEnumclass 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 aConversionExceptionif an error occurs. -
GENERIC_DEFAULT
Shared instance that returnsnullif an error occurs.
-
-
Method Details
-
getDefaultType
- Specified by:
getDefaultTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
convertToType
- Specified by:
convertToTypein 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:
convertToStringin classorg.apache.commons.beanutils.converters.AbstractConverter- Throws:
Throwable
-
register
public static void register()RegistersEnumConverter.GENERICfor theEnumclass in the singleton Apache commons bean utils converter.Note that the default
ConvertUtilsBeanimplementation doesn't fallback toEnumwhen converting enumerations. Instances ofEnumConvertUtilsBeanorEnumConvertUtilsBean2must be used to this converter apply. -
register
public static void register(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERICfor theEnumclass in the specified Apache commons bean utils converter.Note that the default
ConvertUtilsBeanimplementation doesn't fallback toEnumwhen converting enumerations. Instances ofEnumConvertUtilsBeanorEnumConvertUtilsBean2must be used to this converter apply.- Parameters:
converter- The Apache commons bean utils converter to register to
-
registerWithDefault
public static void registerWithDefault()RegistersEnumConverter.GENERIC_DEFAULTfor theEnumclass in the singleton Apache commons bean utils converter.Note that the default
ConvertUtilsBeanimplementation doesn't fallback toEnumwhen converting enumerations. Instances ofEnumConvertUtilsBeanorEnumConvertUtilsBean2must be used to this converter apply. -
registerWithDefault
public static void registerWithDefault(org.apache.commons.beanutils.ConvertUtilsBean converter) RegistersEnumConverter.GENERIC_DEFAULTfor theEnumclass in the specified Apache commons bean utils converter.Note that the default
ConvertUtilsBeanimplementation doesn't fallback toEnumwhen converting enumerations. Instances ofEnumConvertUtilsBeanorEnumConvertUtilsBean2must be used to this converter apply.- Parameters:
converter- The Apache commons bean utils converter to register to
-