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 java.lang.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 (seeStringPrefixSuffixDecorator(java.lang.String, java.lang.String, boolean)
).
-
-
Field Summary
Fields Modifier and Type Field Description protected 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.protected java.lang.String
_prefix
Decoration added before value being decorated: for example, if decorating with brackets, this would be opening bracket[
.protected java.lang.String
_suffix
Decoration added after value being decorated: for example, if decorating with brackets, this would be closing bracket]
.
-
Constructor Summary
Constructors Constructor Description StringPrefixSuffixDecorator(java.lang.String prefix, java.lang.String suffix, boolean optional)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
decorateValue(CsvGenerator gen, java.lang.String plainValue)
Method called during serialization when encoding a value, to produce "decorated" value to include in output (possibly escaped and/or quoted).java.lang.String
undecorateValue(CsvParser parser, java.lang.String decoratedValue)
Method called during deserialization, to remove possible decoration applied withCsvValueDecorator.decorateValue(com.fasterxml.jackson.dataformat.csv.CsvGenerator, java.lang.String)
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.fasterxml.jackson.dataformat.csv.CsvValueDecorator
decorateNull
-
-
-
-
Field Detail
-
_prefix
protected final java.lang.String _prefix
Decoration added before value being decorated: for example, if decorating with brackets, this would be opening bracket[
.
-
_suffix
protected final java.lang.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.
-
-
Method Detail
-
decorateValue
public java.lang.String decorateValue(CsvGenerator gen, java.lang.String plainValue) throws java.io.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 ofCsvSchema
is applied on decorated value.- Specified by:
decorateValue
in interfaceCsvValueDecorator
- Parameters:
gen
- Generator that will be used for actual serializationplainValue
- Value to decorate- Returns:
- Decorated value (which may be
plainValue
as-is) but Must Not benull
- Throws:
java.io.IOException
- if attempt to decorate the value somehow fails (typically aStreamWriteException
)
-
undecorateValue
public java.lang.String undecorateValue(CsvParser parser, java.lang.String decoratedValue) throws java.io.IOException
Description copied from interface:CsvValueDecorator
Method called during deserialization, to remove possible decoration applied withCsvValueDecorator.decorateValue(com.fasterxml.jackson.dataformat.csv.CsvGenerator, java.lang.String)
. Call is made after textual value for a cell (column value) has been read usingparser
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 interfaceCsvValueDecorator
- Parameters:
parser
- Parser that was used to decode textual value from inputdecoratedValue
- 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:
java.io.IOException
- if attempt to un-decorate the value fails (typically aStreamReadException
)
-
-