Package com.opencsv.bean
Class AbstractCsvConverter
java.lang.Object
com.opencsv.bean.AbstractCsvConverter
- All Implemented Interfaces:
CsvConverter
- Direct Known Subclasses:
ConverterCurrency,ConverterDate,ConverterEnum,ConverterNumber,ConverterPrimitiveTypes,ConverterUUID
This implementation of
CsvConverter provides a reasonable default
for CsvConverter.convertToWrite(java.lang.Object) as well as a couple
of common fields.- Since:
- 4.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LocaleThe locale to be used for error messages.protected LocaleThe locale to be used when converting for reading, if a locale is relevant.protected Class<?> The type to which (on reading) or from which (on writing) conversion is being performed.protected LocaleThe locale to be used when converting for writing, if a locale is relevant. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault nullary constructor, so derived classes aren't forced to create a constructor identical to this one.protectedAbstractCsvConverter(Class<?> type, String locale, String writeLocale, Locale errorLocale) Currently the only constructor for this class. -
Method Summary
Modifier and TypeMethodDescriptionconvertToWrite(Object value) This implementation simply callstoString()onvalue.voidsetErrorLocale(Locale errorLocale) Sets the locale for all error messages.voidIf not null or empty, specifies the locale used for converting locale-specific data types for reading.voidSets the class of the type of the data being processed.voidsetWriteLocale(String writeLocale) If not null or empty, specifies the locale used for converting locale-specific data types for writing.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.opencsv.bean.CsvConverter
convertToRead
-
Field Details
-
type
The type to which (on reading) or from which (on writing) conversion is being performed. -
locale
The locale to be used when converting for reading, if a locale is relevant. -
writeLocale
The locale to be used when converting for writing, if a locale is relevant. -
errorLocale
The locale to be used for error messages.
-
-
Constructor Details
-
AbstractCsvConverter
protected AbstractCsvConverter()Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one.- Since:
- 4.3
-
AbstractCsvConverter
protected AbstractCsvConverter(Class<?> type, String locale, String writeLocale, Locale errorLocale) Currently the only constructor for this class.- Parameters:
type- The type to which (on reading) or from which (on writing) is being convertedlocale- The locale to be used when converting for reading, if a locale is relevantwriteLocale- The locale to be used when converting for writing, if a locale is relevanterrorLocale- The locale to be used for error messages
-
-
Method Details
-
convertToWrite
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:
convertToWritein interfaceCsvConverter- 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- This implementation doesn't, but subclasses do, so it must be declared
-
setErrorLocale
Description copied from interface:CsvConverterSets the locale for all error messages.- Specified by:
setErrorLocalein interfaceCsvConverter- Parameters:
errorLocale- Locale for error messages. Ifnull, the default locale is used.
-
setType
Description copied from interface:CsvConverterSets the class of the type of the data being processed.- Specified by:
setTypein interfaceCsvConverter- Parameters:
type- The type of the data being processed
-
setLocale
Description copied from interface:CsvConverterIf not null or empty, specifies the locale used for converting locale-specific data types for reading.- Specified by:
setLocalein interfaceCsvConverter- Parameters:
locale- The name of the locale for locale-sensitive data
-
setWriteLocale
Description copied from interface:CsvConverterIf not null or empty, specifies the locale used for converting locale-specific data types for writing.- Specified by:
setWriteLocalein interfaceCsvConverter- Parameters:
writeLocale- The name of the locale for locale-sensitive data
-