Top Description Fields Constructors Methods
com.opencsv.bean

public Class ConverterPrimitiveTypes

extends AbstractCsvConverter
Class Inheritance
Imports
com.opencsv.ICSVParser, com.opencsv.exceptions.CsvDataTypeMismatchException, org.apache.commons.beanutils.BeanUtilsBean, .ConversionException, .ConvertUtilsBean, org.apache.commons.beanutils.locale.LocaleConvertUtilsBean, org.apache.commons.lang3.StringUtils, java.util.Locale, .ResourceBundle

This class wraps fields from the reflection API in order to handle translation of primitive types and to add a "required" flag.
Author
Andrew Rucker Jones
Since
4.2 (previously BeanFieldPrimitiveTypes since 3.8)

Field Summary

Modifier and TypeField and Description
protected final ConvertUtilsBean
readConverter

The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is not required.

protected final LocaleConvertUtilsBean
readLocaleConverter

The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is required.

protected final ConvertUtilsBean
writeConverter

The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is not required.

protected final LocaleConvertUtilsBean
writeLocaleConverter

The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is required.

Inherited from com.opencsv.bean.AbstractCsvConverter:
errorLocalelocaletypewriteLocale

Constructor Summary

AccessConstructor and Description
public
ConverterPrimitiveTypes(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 method takes the current value of the field in question in the bean passed in and converts it to a string.

Inherited from com.opencsv.bean.AbstractCsvConverter:
setErrorLocalesetLocalesetTypesetWriteLocale

Field Detail

readConverterback to summary
protected final ConvertUtilsBean readConverter

The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is not required.

Either this or readLocaleConverter should be used, and the other should always be null.

It is absolutely critical that access to this member variable is always synchronized!

readLocaleConverterback to summary
protected final LocaleConvertUtilsBean readLocaleConverter

The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is required.

Either this or readConverter should be used, and the other should always be null.

It is absolutely critical that access to this member variable is always synchronized!

writeConverterback to summary
protected final ConvertUtilsBean writeConverter

The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is not required.

Either this or writeLocaleConverter should be used, and the other should always be null.

It is absolutely critical that access to this member variable is always synchronized!

writeLocaleConverterback to summary
protected final LocaleConvertUtilsBean writeLocaleConverter

The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is required.

Either this or writeConverter should be used, and the other should always be null.

It is absolutely critical that access to this member variable is always synchronized!

Constructor Detail

ConverterPrimitiveTypesback to summary
public ConverterPrimitiveTypes(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
Exceptions
CsvDataTypeMismatchException:
If the input string cannot be converted into the proper type
convertToWriteback to summary
public String convertToWrite(Object value) throws CsvDataTypeMismatchException

Overrides com.opencsv.bean.AbstractCsvConverter.convertToWrite.

Implements com.opencsv.bean.CsvConverter.convertToWrite.

This method takes the current value of the field in question in the bean passed in and converts it to a string. It works for all of the primitives, wrapped primitives, java.lang.String, java.math.BigDecimal, and java.math.BigInteger.

Annotations
@Override
Exceptions
CsvDataTypeMismatchException:
If there is an error converting value to a string