Package com.opencsv.bean
Class ConverterPrimitiveTypes
java.lang.Object
com.opencsv.bean.AbstractCsvConverter
com.opencsv.bean.ConverterPrimitiveTypes
- All Implemented Interfaces:
CsvConverter
This class wraps fields from the reflection API in order to handle
translation of primitive types and to add a "required" flag.
- Since:
- 4.2 (previously BeanFieldPrimitiveTypes since 3.8)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.beanutils.ConvertUtilsBean
The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is not required.protected final org.apache.commons.beanutils.locale.LocaleConvertUtilsBean
The formatter for all inputs to wrapped and unwrapped primitive types when a specific locale is required.protected final org.apache.commons.beanutils.ConvertUtilsBean
The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is not required.protected final org.apache.commons.beanutils.locale.LocaleConvertUtilsBean
The formatter for all inputs from wrapped and unwrapped primitive types when a specific locale is required.Fields inherited from class com.opencsv.bean.AbstractCsvConverter
errorLocale, locale, type, writeLocale
-
Constructor Summary
ConstructorsConstructorDescriptionConverterPrimitiveTypes
(Class<?> type, String locale, String writeLocale, Locale errorLocale) -
Method Summary
Modifier and TypeMethodDescriptionconvertToRead
(String value) Method for converting from a string to the proper data type of the destination field.convertToWrite
(Object value) This method takes the current value of the field in question in the bean passed in and converts it to a string.Methods inherited from class com.opencsv.bean.AbstractCsvConverter
setErrorLocale, setLocale, setType, setWriteLocale
-
Field Details
-
readConverter
protected final org.apache.commons.beanutils.ConvertUtilsBean readConverterThe 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 benull
.It is absolutely critical that access to this member variable is always synchronized!
-
readLocaleConverter
protected final org.apache.commons.beanutils.locale.LocaleConvertUtilsBean readLocaleConverterThe 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 benull
.It is absolutely critical that access to this member variable is always synchronized!
-
writeConverter
protected final org.apache.commons.beanutils.ConvertUtilsBean writeConverterThe 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 benull
.It is absolutely critical that access to this member variable is always synchronized!
-
writeLocaleConverter
protected final org.apache.commons.beanutils.locale.LocaleConvertUtilsBean writeLocaleConverterThe 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 benull
.It is absolutely critical that access to this member variable is always synchronized!
-
-
Constructor Details
-
ConverterPrimitiveTypes
public ConverterPrimitiveTypes(Class<?> type, String locale, String writeLocale, Locale errorLocale) - Parameters:
type
- The class of the type of the data being processedlocale
- If not null or empty, specifies the locale used for converting locale-specific data typeswriteLocale
- If not null or empty, specifies the locale used for converting locale-specific data types for writingerrorLocale
- The locale to use for error messages.
-
-
Method Details
-
convertToRead
Description copied from interface:CsvConverter
Method 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
Object
representing the input data converted into the proper type - Throws:
CsvDataTypeMismatchException
- If the input string cannot be converted into the proper type
-
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,String
,BigDecimal
, andBigInteger
.- Specified by:
convertToWrite
in interfaceCsvConverter
- Overrides:
convertToWrite
in classAbstractCsvConverter
- Parameters:
value
- The contents of the field currently being processed from the bean to be written. Can benull
if 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
value
isnull
- Throws:
CsvDataTypeMismatchException
- If there is an error converting value to a string
-