Class ConverterNumber

All Implemented Interfaces:
CsvConverter

public class ConverterNumber extends AbstractCsvConverter
This converter class is used in combination with CsvNumber, that is, when number inputs and outputs should be formatted.
Since:
4.2
  • Field Details

  • Constructor Details

    • ConverterNumber

      public ConverterNumber(Class<?> type, String locale, String writeLocale, Locale errorLocale, String readFormat, String writeFormat) throws CsvBadConverterException
      Parameters:
      type - The class of the type of the data being processed
      locale - If not null or empty, specifies the locale used for converting locale-specific data types for reading
      writeLocale - If not null or empty, specifies the locale used for converting locale-specific data types for writing
      errorLocale - The locale to use for error messages
      readFormat - The string to use for parsing the number.
      writeFormat - The string to use for formatting the number.
      Throws:
      CsvBadConverterException - If the information given to initialize the converter are inconsistent (e.g. the annotation CsvNumber has been applied to a non-Number type.
      See Also:
  • Method Details

    • createDecimalFormat

      private DecimalFormat createDecimalFormat(String format, Locale locale)
    • convertToRead

      public Object convertToRead(String value) throws CsvDataTypeMismatchException
      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 be null, empty or blank according to StringUtils.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

      public String convertToWrite(Object value)
      Formats the number in question according to the pattern that has been provided.
      Specified by:
      convertToWrite in interface CsvConverter
      Overrides:
      convertToWrite in class AbstractCsvConverter
      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