-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #442: allow registering handlers for "decorating" values (like Ar…
…rays) (#443)
- Loading branch information
1 parent
2d784b2
commit bb06df1
Showing
7 changed files
with
629 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvValueDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.fasterxml.jackson.dataformat.csv; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* 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. | ||
*<p> | ||
* Decorations are handled after handling other encoding aspects such as | ||
* optional quoting and/or escaping. | ||
*<p> | ||
* Decorators can be registered on specific columns of {@link CsvSchema}. | ||
* | ||
* @since 2.18 | ||
*/ | ||
public 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 {@link CsvSchema} is applied on decorated value. | ||
* | ||
* @param gen Generator that will be used for actual serialization | ||
* @param plainValue Value to decorate | ||
* | ||
* @return Decorated value (which may be {@code plainValue} as-is) | ||
* | ||
* @throws IOException if attempt to decorate the value somehow fails | ||
* (typically a {@link com.fasterxml.jackson.core.exc.StreamWriteException}) | ||
*/ | ||
public String decorateValue(CsvGenerator gen, String plainValue) | ||
throws IOException; | ||
|
||
/** | ||
* Method called during deserialization, to remove possible decoration | ||
* applied with {@link #decorateValue}. | ||
* Call is made after textual value for a cell (column | ||
* value) has been read using {@code parser} and after removing (decoding) | ||
* possible quoting and/or escaping of the value. Value passed in | ||
* has no escaping or quoting left. | ||
* | ||
* @param parser Parser that was used to decode textual value from input | ||
* @param decoratedValue Value from which to remove decorations, if any | ||
* (some decorators can allow optional decorations; others may fail | ||
* if none found) | ||
* | ||
* @return Value after removing decorations, if any. | ||
* | ||
* @throws IOException if attempt to un-decorate the value fails | ||
* (typically a {@link com.fasterxml.jackson.core.exc.StreamReadException}) | ||
*/ | ||
public String undecorateValue(CsvParser parser, String decoratedValue) | ||
throws IOException; | ||
} |
Oops, something went wrong.