-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for multiple tag escaping strategies
- Loading branch information
Showing
8 changed files
with
301 additions
and
81 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
src/main/java/com/fasterxml/jackson/dataformat/xml/TagEscapingStrategy.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,108 @@ | ||
package com.fasterxml.jackson.dataformat.xml; | ||
|
||
/** | ||
* Strategy for dealing with tags containing invalid characters. Invalid | ||
* characters in tags can, for instance, easily appear in map keys. | ||
* | ||
* @since 2.14 | ||
*/ | ||
public enum TagEscapingStrategy { | ||
/** | ||
* Present for backwards compatibility. Using this option may produce | ||
* invalid XML that can no longer be processed. For instance, this | ||
* can easily happen for map keys containing special characters or spaces. | ||
* <p> | ||
* With this feature set, a map with the keys {@code "123"} and | ||
* {@code "$ I am <fancy>! &;"} will be written as: | ||
* | ||
* <pre>{@code | ||
* <DTO> | ||
* <badMap> | ||
* <$ I am <fancy>! &;>xyz</$ I am <fancy>! &;> | ||
* <123>bar</123> | ||
* </badMap> | ||
* </DTO> | ||
* }</pre> | ||
* | ||
* <b>Note:</b> This option ignored for deserialization, since even | ||
* Jackson can't parse invalid XML. | ||
* | ||
* @since 2.14 | ||
*/ | ||
NONE, | ||
|
||
/** | ||
* Replaces all invalid characters in a tag with a {@code _}. Using this | ||
* option will produce valid XML, but the generated XML will not be | ||
* 100% reversible (as in serializing and deserializing an object may not | ||
* produce the same object again). | ||
* <p> | ||
* With this feature set, a map with the keys {@code "123"} and | ||
* {@code "$ I am <fancy>! &;"} will be written as: | ||
* | ||
* <pre>{@code | ||
* <DTO> | ||
* <badMap> | ||
* <__I_am__fancy_____>xyz</__I_am__fancy_____> | ||
* <_23>bar</_23> | ||
* </badMap> | ||
* </DTO> | ||
* }</pre> | ||
* | ||
* <b>Note:</b> This option ignored for deserialization, since there is no | ||
* way to reverse this step. | ||
* | ||
* @since 2.14 | ||
*/ | ||
REPLACE, | ||
|
||
/** | ||
* Strategy that indicates that invalid XML tag names should be escaped | ||
* via an attribute ({@code real_name}) in a standard tag. | ||
* <p> | ||
* With this feature set, a map with the keys {@code "123"} and | ||
* {@code "$ I am <fancy>! &;"} will be written as: | ||
* | ||
* <pre>{@code | ||
* <DTO> | ||
* <badMap> | ||
* <escaped_tag real_name="$ I am <fancy>! &;">xyz</escaped_tag> | ||
* <escaped_tag real_name="123">bar</escaped_tag> | ||
* </badMap> | ||
* </DTO> | ||
* }</pre> | ||
* | ||
* @since 2.14 | ||
*/ | ||
ATTRIBUTE_ESCAPE, | ||
|
||
/** | ||
* With this strategy the entire tag is escaped via base64 with the prefix | ||
* {@code base64_tag_}. Here the | ||
* <a href="https://datatracker.ietf.org/doc/html/rfc4648#section-5">base64url</a> | ||
* encoder and decoders are used. The {@code =} padding characters are | ||
* always omitted. | ||
* <p> | ||
* With this feature set, a map with the keys {@code "123"} and | ||
* {@code "$ I am <fancy>! &;"} will be written as: | ||
* | ||
* <pre>{@code | ||
* <DTO> | ||
* <badMap> | ||
* <base64_tag_JCBJIGFtIDxmYW5jeT4hICY7>xyz</base64_tag_JCBJIGFtIDxmYW5jeT4hICY7> | ||
* <base64_tag_MTIz>bar</base64_tag_MTIz> | ||
* </badMap> | ||
* </DTO> | ||
* }</pre> | ||
* | ||
* @since 2.14 | ||
*/ | ||
BASE64, | ||
|
||
; | ||
|
||
public static final String ESCAPED_TAG_NAME = "escaped_tag"; | ||
public static final String ESCAPED_ATTR_NS = ""; // "jackson"; | ||
public static final String ESCAPED_ATTR_NAME = "real_name"; | ||
public static final String ESCAPED_BASE64_PREFIX = "base64_tag_"; | ||
} |
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
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
Oops, something went wrong.