Class ConverterEnum
java.lang.Object
com.opencsv.bean.AbstractCsvConverter
com.opencsv.bean.ConverterEnum
- All Implemented Interfaces:
CsvConverter
This class converts an input to an enumeration type and vice versa.
The input string must match the enumeration value as declared, ignoring
case. The output value will always be the enumeration value, exactly as
declared.
- Since:
- 5.2
-
Field Summary
Fields inherited from class AbstractCsvConverter
errorLocale, locale, type, writeLocale -
Constructor Summary
ConstructorsConstructorDescriptionConverterEnum(Class<?> type, String locale, String writeLocale, Locale errorLocale) -
Method Summary
Modifier and TypeMethodDescriptionconvertToRead(String value) Method for converting from a string to the proper data type of the destination field.convertToWrite(Object value) This implementation simply callstoString()onvalue.Methods inherited from class AbstractCsvConverter
setErrorLocale, setLocale, setType, setWriteLocale
-
Constructor Details
-
ConverterEnum
- Parameters:
type- The class of the type of the data being processedlocale- If not null or empty, specifies the locale used for converting locale-specific data typeswriteLocale- If not null or empty, specifies the locale used for converting locale-specific data types for writingerrorLocale- The locale to use for error messages.
-
-
Method Details
-
convertToRead
Description copied from interface:CsvConverterMethod for converting from a string to the proper data type of the destination field.- Parameters:
value- The string from the selected field of the CSV file. If the field is marked as required in the annotation, this value is guaranteed not to benull, empty or blank according toStringUtils.isBlank(java.lang.CharSequence)- Returns:
- An
Objectrepresenting the input data converted into the proper type - Throws:
CsvDataTypeMismatchException- If the input string cannot be converted into the proper type
-
convertToWrite
Description copied from class:AbstractCsvConverterThis implementation simply callstoString()onvalue. For complex types, overriding thetoString()method in the type of the field in question would be an alternative to writing a conversion routine in a class derived from this one.- Specified by:
convertToWritein interfaceCsvConverter- Overrides:
convertToWritein classAbstractCsvConverter- Parameters:
value- The contents of the field currently being processed from the bean to be written. Can benullif the field is not marked as required.- Returns:
- A string representation of the value of the field in question in
the bean passed in, or an empty string if
valueisnull
-