Top Description Fields Constructors Methods
com.opencsv.bean

public Class ConverterEnum

extends AbstractCsvConverter
Class Inheritance
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.CsvDataTypeMismatchException, org.apache.commons.lang3.EnumUtils, .StringUtils, java.util.Locale, .ResourceBundle

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.
Author
Andrew Rucker Jones
Since
5.2

Field Summary

Inherited from com.opencsv.bean.AbstractCsvConverter:
errorLocalelocaletypewriteLocale

Constructor Summary

AccessConstructor and Description
public
ConverterEnum(Class<?>
The class of the type of the data being processed
type
,
String
If not null or empty, specifies the locale used for converting locale-specific data types
locale
,
String
If not null or empty, specifies the locale used for converting locale-specific data types for writing
writeLocale
,
Locale
The locale to use for error messages.
errorLocale
)

Method Summary

Modifier and TypeMethod and Description
public Object
convertToRead(String value)

Implements com.opencsv.bean.CsvConverter.convertToRead.

Method for converting from a string to the proper data type of the destination field.

public String
convertToWrite(Object value)

Overrides com.opencsv.bean.AbstractCsvConverter.convertToWrite.

Implements com.opencsv.bean.CsvConverter.convertToWrite.

This implementation simply calls toString() on value.

Inherited from com.opencsv.bean.AbstractCsvConverter:
setErrorLocalesetLocalesetTypesetWriteLocale

Constructor Detail

ConverterEnumback to summary
public ConverterEnum(Class<?> type, String locale, String writeLocale, Locale errorLocale)
Parameters
type:Class<?>

The class of the type of the data being processed

locale:String

If not null or empty, specifies the locale used for converting locale-specific data types

writeLocale:String

If not null or empty, specifies the locale used for converting locale-specific data types for writing

errorLocale:Locale

The locale to use for error messages.

Method Detail

convertToReadback to summary
public Object convertToRead(String value) throws CsvDataTypeMismatchException

Implements com.opencsv.bean.CsvConverter.convertToRead.

Doc from com.opencsv.bean.CsvConverter.convertToRead.

Method for converting from a string to the proper data type of the destination field.

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
CsvDataTypeMismatchException:
If the input string cannot be converted into the proper type
convertToWriteback to summary
public String convertToWrite(Object value)

Overrides com.opencsv.bean.AbstractCsvConverter.convertToWrite.

Implements com.opencsv.bean.CsvConverter.convertToWrite.

Doc from com.opencsv.bean.AbstractCsvConverter.convertToWrite.

This implementation simply calls toString() on value. For complex types, overriding the toString() 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.

Annotations
@Override