Class CsvValueDecorators.StringPrefixSuffixDecorator

java.lang.Object
com.fasterxml.jackson.dataformat.csv.CsvValueDecorators.StringPrefixSuffixDecorator
All Implemented Interfaces:
CsvValueDecorator
Enclosing class:
CsvValueDecorators

public static class CsvValueDecorators.StringPrefixSuffixDecorator extends Object implements CsvValueDecorator
Decorated that adds static prefix and suffix around value to decorate value; removes the same when un-decorating. Handling of the case where decoration is missing on deserialization (reading) depends on where decorator is created with "optional" or "strict" setting (see StringPrefixSuffixDecorator(java.lang.String, java.lang.String, boolean)).
  • Field Details

    • _prefix

      protected final String _prefix
      Decoration added before value being decorated: for example, if decorating with brackets, this would be opening bracket [ .
    • _suffix

      protected final String _suffix
      Decoration added after value being decorated: for example, if decorating with brackets, this would be closing bracket ] .
    • _optional

      protected final boolean _optional
      Whether existence of prefix and suffix decoration is optional (true) or required (false): if required and value does does not have decorations, deserialization (reading) will fail with an exception; if optional value is exposed as is.
  • Constructor Details

    • StringPrefixSuffixDecorator

      public StringPrefixSuffixDecorator(String prefix, String suffix, boolean optional)
  • Method Details

    • decorateValue

      public String decorateValue(CsvGenerator gen, String plainValue) throws IOException
      Description copied from interface: CsvValueDecorator
      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.
      Specified by:
      decorateValue in interface CsvValueDecorator
      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)
    • undecorateValue

      public String undecorateValue(CsvParser parser, String decoratedValue) throws IOException
      Description copied from interface: CsvValueDecorator
      Method called during deserialization, to remove possible decoration applied with CsvValueDecorator.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.
      Specified by:
      undecorateValue in interface CsvValueDecorator
      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)