Package com.opencsv.bean
Interface CsvConverter
-
- All Known Implementing Classes:
AbstractCsvConverter,ConverterCurrency,ConverterDate,ConverterEnum,ConverterNumber,ConverterPrimitiveTypes,ConverterUUID
public interface CsvConverterClasses 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.
- Since:
- 4.2
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.ObjectconvertToRead(java.lang.String value)Method for converting from a string to the proper data type of the destination field.java.lang.StringconvertToWrite(java.lang.Object value)Method for converting from the data type of the destination field to a string.voidsetErrorLocale(java.util.Locale errorLocale)Sets the locale for all error messages.voidsetLocale(java.lang.String locale)If not null or empty, specifies the locale used for converting locale-specific data types for reading.voidsetType(java.lang.Class<?> type)Sets the class of the type of the data being processed.voidsetWriteLocale(java.lang.String writeLocale)If not null or empty, specifies the locale used for converting locale-specific data types for writing.
-
-
-
Method Detail
-
convertToRead
java.lang.Object convertToRead(java.lang.String value) throws CsvDataTypeMismatchException, CsvConstraintViolationExceptionMethod 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 typeCsvConstraintViolationException- When the internal structure of data would be violated by the data in the CSV file
-
convertToWrite
java.lang.String convertToWrite(java.lang.Object value) throws CsvDataTypeMismatchExceptionMethod for converting from the data type of the destination field to a string.- 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 - Throws:
CsvDataTypeMismatchException- If the input cannot be converted to a string by this converter
-
setErrorLocale
void setErrorLocale(java.util.Locale errorLocale)
Sets the locale for all error messages.- Parameters:
errorLocale- Locale for error messages. Ifnull, the default locale is used.
-
setType
void setType(java.lang.Class<?> type)
Sets the class of the type of the data being processed.- Parameters:
type- The type of the data being processed- Since:
- 4.3
-
setLocale
void setLocale(java.lang.String locale)
If not null or empty, specifies the locale used for converting locale-specific data types for reading.- Parameters:
locale- The name of the locale for locale-sensitive data- Since:
- 4.3
-
setWriteLocale
void setWriteLocale(java.lang.String writeLocale)
If not null or empty, specifies the locale used for converting locale-specific data types for writing.- Parameters:
writeLocale- The name of the locale for locale-sensitive data- Since:
- 5.0
-
-