Class ConvertNullTo

java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.ConvertNullTo
All Implemented Interfaces:
BoolCellProcessor, CellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor
Direct Known Subclasses:
Optional

This processor returns a specified default value if the input is null. This is handy when writing partially filled beans, maps and arrays, as for each column a default value can be specified.

To return the String "" when a null is encountered use new ConvertNullTo("\"\"");

If you need further processing of the value in case the value is not null, you can link the processor with other processors such as new ConvertNullTo("\"\"", new Truncate(3))

Since:
1.20
  • Field Details

    • returnValue

      private final Object returnValue
  • Constructor Details

    • ConvertNullTo

      public ConvertNullTo(Object returnValue)
      Constructs a new ConvertNullTo processor, which returns a specified default value if the input is null.
      Parameters:
      returnValue - the value to return if the input is null
    • ConvertNullTo

      public ConvertNullTo(Object returnValue, CellProcessor next)
      Constructs a new ConvertNullTo processor, which returns a specified default value if the input is null. If the input is not null, then the next processor is executed.
      Parameters:
      returnValue - the value to return if the input is null
      next - the next CellProcessor in the chain
      Throws:
      NullPointerException - if next is null
  • Method Details

    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution