public class ConverterDate extends AbstractCsvConverter
This class should work with any type derived from Date
as long as it has a constructor taking one long that specifies the number
of milliseconds since the epoch. The following types are explicitly
supported:
This class should work for any type that implements
Calendar
or is derived from
XMLGregorianCalendar
. The following types are
explicitly supported:
This class works for all types from the JDK that implement
TemporalAccessor
.
CsvDate
errorLocale, locale, type, writeLocale
Constructor and Description |
---|
ConverterDate(Class<?> type,
String locale,
String writeLocale,
Locale errorLocale,
String readFormat,
String writeFormat,
String readChronology,
String writeChronology)
Initializes the class.
|
Modifier and Type | Method and Description |
---|---|
Object |
convertToRead(String value)
Method for converting from a string to the proper data type of the
destination field.
|
String |
convertToWrite(Object value)
This method converts the encapsulated date type to a string, respecting
any locales and conversion patterns that have been set through opencsv
annotations.
|
setErrorLocale, setLocale, setType, setWriteLocale
public ConverterDate(Class<?> type, String locale, String writeLocale, Locale errorLocale, String readFormat, String writeFormat, String readChronology, String writeChronology)
type
- The type of the field being populatedreadFormat
- The string to use for parsing the date. See
CsvDate.value()
writeFormat
- The string to use for formatting the date. See
CsvDate.writeFormat()
locale
- 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 messagesreadChronology
- The Chronology
to be used
for reading if
TemporalAccessor
-based
fields are in usewriteChronology
- The Chronology
to be
used for writing if
TemporalAccessor
-based
fields are in usepublic Object convertToRead(String value) throws CsvDataTypeMismatchException
CsvConverter
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 be null
, empty or blank according to
StringUtils.isBlank(java.lang.CharSequence)
Object
representing the input data converted
into the proper typeCsvDataTypeMismatchException
- If the input string cannot be converted into
the proper typepublic String convertToWrite(Object value) throws CsvDataTypeMismatchException
convertToWrite
in interface CsvConverter
convertToWrite
in class AbstractCsvConverter
value
- The object containing a date of one of the supported typeslocale
or conversion
pattern
has been specified through annotations, these are used when
creating the return value.CsvDataTypeMismatchException
- If an unsupported type as been
improperly annotatedCopyright © 2005–2023. All rights reserved.