Interface CsvValueDecorator

All Known Implementing Classes:
CsvValueDecorators.StringPrefixSuffixDecorator

public interface CsvValueDecorator
Interface defining API for handlers that can add and remove "decorations" to CSV values: for example, brackets around Array (List) values encoded in a single physical String column.

Decorations are handled after handling other encoding aspects such as optional quoting and/or escaping.

Decorators can be registered on specific columns of CsvSchema.

Since:
2.18
  • Method Details

    • decorateValue

      String decorateValue(CsvGenerator gen, String plainValue) throws IOException
      Method called during serialization when encoding a value, to produce "decorated" value to include in output (possibly escaped and/or quoted). Note that possible escaping and/or quoting (as per configuration of CsvSchema is applied on decorated value.
      Parameters:
      gen - Generator that will be used for actual serialization
      plainValue - Value to decorate
      Returns:
      Decorated value (which may be plainValue as-is) but Must Not be null
      Throws:
      IOException - if attempt to decorate the value somehow fails (typically a StreamWriteException)
    • decorateNull

      default String decorateNull(CsvGenerator gen) throws IOException
      Method called instead of decorateValue(com.fasterxml.jackson.dataformat.csv.CsvGenerator, java.lang.String) in case where value being written is from Java null value: this is often left as-is, without decoration (and this is the default implementation), but may be decorated. To let default Null Value Replacement be used, should return null: this is the default implementation.
      Parameters:
      gen - Generator that will be used for actual serialization
      Returns:
      Decorated value to use, IF NOT null: if null will use default null replacement value.
      Throws:
      IOException - if attempt to decorate the value somehow fails (typically a StreamWriteException)
    • undecorateValue

      String undecorateValue(CsvParser parser, String decoratedValue) throws IOException
      Method called during deserialization, to remove possible decoration applied with decorateValue(com.fasterxml.jackson.dataformat.csv.CsvGenerator, java.lang.String). Call is made after textual value for a cell (column value) has been read using parser and after removing (decoding) possible quoting and/or escaping of the value. Value passed in has no escaping or quoting left.
      Parameters:
      parser - Parser that was used to decode textual value from input
      decoratedValue - Value from which to remove decorations, if any (some decorators can allow optional decorations; others may fail if none found)
      Returns:
      Value after removing decorations, if any.
      Throws:
      IOException - if attempt to un-decorate the value fails (typically a StreamReadException)