Top Description Fields Constructors Methods
com.opencsv.bean

public abstract Class AbstractCsvConverter

extends Object
implements CsvConverter
Class Inheritance
All Implemented Interfaces
com.opencsv.bean.CsvConverter
Known Direct Subclasses
com.opencsv.bean.ConverterCurrency, com.opencsv.bean.ConverterDate, com.opencsv.bean.ConverterNumber, com.opencsv.bean.ConverterPrimitiveTypes, com.opencsv.bean.ConverterUUID, com.opencsv.bean.ConverterEnum
Imports
com.opencsv.exceptions.CsvDataTypeMismatchException, org.apache.commons.lang3.ObjectUtils, .StringUtils, java.util.Locale, .Objects

This implementation of CsvConverter provides a reasonable default for CsvConverter#convertToWrite(java.lang.Object) as well as a couple of common fields.
Author
Andrew Rucker Jones
Since
4.2

Field Summary

Modifier and TypeField and Description
protected Locale
errorLocale

The locale to be used for error messages.

protected Locale
locale

The locale to be used when converting for reading, if a locale is relevant.

protected Class<?>
type

The type to which (on reading) or from which (on writing) conversion is being performed.

protected Locale
writeLocale

The locale to be used when converting for writing, if a locale is relevant.

Constructor Summary

AccessConstructor and Description
protected
AbstractCsvConverter()

Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one.

protected
AbstractCsvConverter(Class<?>
The type to which (on reading) or from which (on writing) is being converted
type
,
String
The locale to be used when converting for reading, if a locale is relevant
locale
,
String
The locale to be used when converting for writing, if a locale is relevant
writeLocale
,
Locale
The locale to be used for error messages
errorLocale
)

Currently the only constructor for this class.

Method Summary

Modifier and TypeMethod and Description
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
)

Implements com.opencsv.bean.CsvConverter.convertToWrite.

This implementation simply calls toString() on value.

public void
setErrorLocale(Locale errorLocale)

Implements com.opencsv.bean.CsvConverter.setErrorLocale.

Sets the locale for all error messages.

public void
setLocale(String locale)

Implements com.opencsv.bean.CsvConverter.setLocale.

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

public void
setType(Class<?> type)

Implements com.opencsv.bean.CsvConverter.setType.

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

public void
setWriteLocale(String writeLocale)

Implements com.opencsv.bean.CsvConverter.setWriteLocale.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorLocaleback to summary
protected Locale errorLocale

The locale to be used for error messages.

localeback to summary
protected Locale locale

The locale to be used when converting for reading, if a locale is relevant.

typeback to summary
protected Class<?> type

The type to which (on reading) or from which (on writing) conversion is being performed.

writeLocaleback to summary
protected Locale writeLocale

The locale to be used when converting for writing, if a locale is relevant.

Constructor Detail

AbstractCsvConverterback to summary
protected AbstractCsvConverter()

Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one.

Since
4.3
AbstractCsvConverterback to summary
protected AbstractCsvConverter(Class<?> type, String locale, String writeLocale, Locale errorLocale)

Currently the only constructor for this class.

Parameters
type:Class<?>

The type to which (on reading) or from which (on writing) is being converted

locale:String

The locale to be used when converting for reading, if a locale is relevant

writeLocale:String

The locale to be used when converting for writing, if a locale is relevant

errorLocale:Locale

The locale to be used for error messages

Method Detail

convertToWriteback to summary
public String convertToWrite(Object value) throws CsvDataTypeMismatchException

Implements com.opencsv.bean.CsvConverter.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.

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

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:
This implementation doesn't, but subclasses do, so it must be declared
setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Implements com.opencsv.bean.CsvConverter.setErrorLocale.

Doc from com.opencsv.bean.CsvConverter.setErrorLocale.

Sets the locale for all error messages.

Annotations
@Override
setLocaleback to summary
public void setLocale(String locale)

Implements com.opencsv.bean.CsvConverter.setLocale.

Doc from com.opencsv.bean.CsvConverter.setLocale.

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

Annotations
@Override
setTypeback to summary
public void setType(Class<?> type)

Implements com.opencsv.bean.CsvConverter.setType.

Doc from com.opencsv.bean.CsvConverter.setType.

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

Annotations
@Override
setWriteLocaleback to summary
public void setWriteLocale(String writeLocale)

Implements com.opencsv.bean.CsvConverter.setWriteLocale.

Doc from com.opencsv.bean.CsvConverter.setWriteLocale.

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

Annotations
@Override