Class AbstractCsvConverter

java.lang.Object
com.opencsv.bean.AbstractCsvConverter
All Implemented Interfaces:
CsvConverter
Direct Known Subclasses:
ConverterCurrency, ConverterDate, ConverterEnum, ConverterNumber, ConverterPrimitiveTypes, ConverterUUID

public abstract class AbstractCsvConverter extends Object implements CsvConverter
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

    Fields
    Modifier and Type
    Field
    Description
    protected Locale
    The locale to be used for error messages.
    protected Locale
    The 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 Locale
    The locale to be used when converting for writing, if a locale is relevant.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default nullary constructor, so derived classes aren't forced to create a constructor identical to this one.
    protected
    AbstractCsvConverter(Class<?> type, String locale, String writeLocale, Locale errorLocale)
    Currently the only constructor for this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    This implementation simply calls toString() on value.
    void
    setErrorLocale(Locale errorLocale)
    Sets the locale for all error messages.
    void
    setLocale(String locale)
    If not null or empty, specifies the locale used for converting locale-specific data types for reading.
    void
    setType(Class<?> type)
    Sets the class of the type of the data being processed.
    void
    setWriteLocale(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, wait

    Methods inherited from interface com.opencsv.bean.CsvConverter

    convertToRead
  • Field Details

    • type

      protected Class<?> type
      The type to which (on reading) or from which (on writing) conversion is being performed.
    • locale

      protected Locale locale
      The locale to be used when converting for reading, if a locale is relevant.
    • writeLocale

      protected Locale writeLocale
      The locale to be used when converting for writing, if a locale is relevant.
    • errorLocale

      protected Locale 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 converted
      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
  • Method Details

    • convertToWrite

      public String convertToWrite(Object value) throws CsvDataTypeMismatchException
      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.
      Specified by:
      convertToWrite in interface CsvConverter
      Parameters:
      value - 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:
      A string representation of the value of the field in question in the bean passed in, or an empty string if value is null
      Throws:
      CsvDataTypeMismatchException - This implementation doesn't, but subclasses do, so it must be declared
    • setErrorLocale

      public void setErrorLocale(Locale errorLocale)
      Description copied from interface: CsvConverter
      Sets the locale for all error messages.
      Specified by:
      setErrorLocale in interface CsvConverter
      Parameters:
      errorLocale - Locale for error messages. If null, the default locale is used.
    • setType

      public void setType(Class<?> type)
      Description copied from interface: CsvConverter
      Sets the class of the type of the data being processed.
      Specified by:
      setType in interface CsvConverter
      Parameters:
      type - The type of the data being processed
    • setLocale

      public void setLocale(String locale)
      Description copied from interface: CsvConverter
      If not null or empty, specifies the locale used for converting locale-specific data types for reading.
      Specified by:
      setLocale in interface CsvConverter
      Parameters:
      locale - The name of the locale for locale-sensitive data
    • setWriteLocale

      public void setWriteLocale(String writeLocale)
      Description copied from interface: CsvConverter
      If not null or empty, specifies the locale used for converting locale-specific data types for writing.
      Specified by:
      setWriteLocale in interface CsvConverter
      Parameters:
      writeLocale - The name of the locale for locale-sensitive data