Top Description Methods
com.opencsv.bean

public Interface CsvConverter

Known Direct Implementers
com.opencsv.bean.AbstractCsvConverter
Imports
com.opencsv.exceptions.CsvConstraintViolationException, .CsvDataTypeMismatchException, java.util.Locale

Classes implementing this interface perform a conversion from String to some type on reading and some type to String on writing.

This interface is used by BeanField to perform the actual data conversion.

Synchronization

All implementations of this interface must be thread-safe.

Author
Andrew Rucker Jones
Since
4.2

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

An java.lang.Object representing the input data converted into the proper type
convertToRead
(String
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 be null, empty or blank according to org.apache.commons.lang3.StringUtils#isBlank(java.lang.CharSequence)
value
)

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

public String

Returns:

A string representation of the value of the field in question in the bean passed in, or an empty string if value is null
convertToWrite
(Object
The contents of the field currently being processed from the bean to be written. Can be null if the field is not marked as required.
value
)

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

public void
setErrorLocale(Locale
Locale for error messages. If null, the default locale is used.
errorLocale
)

Sets the locale for all error messages.

public void
setLocale(String
The name of the locale for locale-sensitive data
locale
)

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

public void
setType(Class<?>
The type of the data being processed
type
)

Sets the class of the type of the data being processed.

public void
setWriteLocale(String
The name of the locale for locale-sensitive data
writeLocale
)

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

Method Detail

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

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

Parameters
value:String

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 be null, empty or blank according to org.apache.commons.lang3.StringUtils#isBlank(java.lang.CharSequence)

Returns:Object

An java.lang.Object representing the input data converted into the proper type

Exceptions
CsvDataTypeMismatchException:
If the input string cannot be converted into the proper type
CsvConstraintViolationException:
When the internal structure of data would be violated by the data in the CSV file
convertToWriteback to summary
public String convertToWrite(Object value) throws CsvDataTypeMismatchException

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

Parameters
value:Object

The contents of the field currently being processed from the bean to be written. Can be null if the field is not marked as required.

Returns:String

A string representation of the value of the field in question in the bean passed in, or an empty string if value is null

Exceptions
CsvDataTypeMismatchException:
If the input cannot be converted to a string by this converter
setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Sets the locale for all error messages.

Parameters
errorLocale:Locale

Locale for error messages. If null, the default locale is used.

setLocaleback to summary
public void setLocale(String locale)

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

Parameters
locale:String

The name of the locale for locale-sensitive data

Since
4.3
setTypeback to summary
public void setType(Class<?> type)

Sets the class of the type of the data being processed.

Parameters
type:Class<?>

The type of the data being processed

Since
4.3
setWriteLocaleback to summary
public void setWriteLocale(String writeLocale)

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

Parameters
writeLocale:String

The name of the locale for locale-sensitive data

Since
5.0