Class ConvertEmptyOrBlankStringsToDefault

java.lang.Object
com.opencsv.bean.processor.ConvertEmptyOrBlankStringsToDefault
All Implemented Interfaces:
StringProcessor

public class ConvertEmptyOrBlankStringsToDefault extends Object implements StringProcessor
StringProcessor that converts the empty or blank strings to a desired value string. This is useful when you want a default value.

A sample of this can be found in the unit test ProcessorTestBean and is annotated as follows.

     @PreAssignmentProcessor(processor = ConvertEmptyOrBlankStringsToDefault.class, paramString = "-1")
     @CsvBindByName(column = "id")
     private int beanId;
 
Since:
5.4
  • Field Details

    • defaultValue

      String defaultValue
  • Constructor Details

    • ConvertEmptyOrBlankStringsToDefault

      public ConvertEmptyOrBlankStringsToDefault()
      Default constructor
  • Method Details

    • processString

      public String processString(String value)
      Description copied from interface: StringProcessor
      Method that contains the code that will transform a string into the value that will be validated and converted into the bean field.
      Specified by:
      processString in interface StringProcessor
      Parameters:
      value - String to be processed
      Returns:
      The processed String
    • setParameterString

      public void setParameterString(String value)
      Description copied from interface: StringProcessor
      This allows the validator extending StringProcessor to be used by multiple fields by allowing you to pass in data for the processor to be used.

      The data could be a default value or whatever the custom processor requires to convert the data.

      If the processor needs multiple parameters, then you will need to combine them into a single string using some sort of delimiter, say a comma, and parse them out using some library that allows you to parse such strings 😁.

      If the processor does not need a value then just create an empty method like the ConvertEmptyOrBlankStringsToNull processor used by the BeanFieldProcessorTest.

      Specified by:
      setParameterString in interface StringProcessor
      Parameters:
      value - Information used by the processor to process the string