Package com.opencsv.bean
Class ConverterEnum
- java.lang.Object
-
- com.opencsv.bean.AbstractCsvConverter
-
- com.opencsv.bean.ConverterEnum
-
- All Implemented Interfaces:
CsvConverter
public class ConverterEnum extends AbstractCsvConverter
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 com.opencsv.bean.AbstractCsvConverter
errorLocale, locale, type, writeLocale
-
-
Constructor Summary
Constructors Constructor Description ConverterEnum(java.lang.Class<?> type, java.lang.String locale, java.lang.String writeLocale, java.util.Locale errorLocale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
convertToRead(java.lang.String value)
Method for converting from a string to the proper data type of the destination field.java.lang.String
convertToWrite(java.lang.Object value)
This implementation simply callstoString()
onvalue
.-
Methods inherited from class com.opencsv.bean.AbstractCsvConverter
setErrorLocale, setLocale, setType, setWriteLocale
-
-
-
-
Constructor Detail
-
ConverterEnum
public ConverterEnum(java.lang.Class<?> type, java.lang.String locale, java.lang.String writeLocale, java.util.Locale errorLocale)
- 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 Detail
-
convertToRead
public java.lang.Object convertToRead(java.lang.String value) throws CsvDataTypeMismatchException
Description copied from interface:CsvConverter
Method 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
Object
representing the input data converted into the proper type - Throws:
CsvDataTypeMismatchException
- If the input string cannot be converted into the proper type
-
convertToWrite
public java.lang.String convertToWrite(java.lang.Object value)
Description copied from class:AbstractCsvConverter
This 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:
convertToWrite
in interfaceCsvConverter
- Overrides:
convertToWrite
in classAbstractCsvConverter
- Parameters:
value
- The contents of the field currently being processed from the bean to be written. Can benull
if 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
value
isnull
-
-