Class XmlNameProcessors
- java.lang.Object
-
- com.fasterxml.jackson.dataformat.xml.XmlNameProcessors
-
public final class XmlNameProcessors extends java.lang.Object
Contains defaultXmlNameProcessor
implementations.Processors should be set in the
XmlMapper.setXmlNameProcessor(XmlNameProcessor)
and/or theXmlMapper.Builder.xmlNameProcessor(XmlNameProcessor)
methods.- Since:
- 2.14
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XmlNameProcessor
newAlwaysOnBase64Processor()
Similar tonewBase64Processor(String)
, however, names will always be escaped with base64.static XmlNameProcessor
newBase64Processor()
Convenience method equivalent to callingnewBase64Processor(String)
with"base64_tag_"
static XmlNameProcessor
newBase64Processor(java.lang.String prefix)
Generates a new processor that escapes all names that contains characters OTHER than following characters: Lower- or upper-case ASCII letter (a to z, A to Z) Digit (0 to 9) in position OTHER than the first characters Underscore Hyphen (-
) in position OTHER than the first character Colon (only exposed if underlying parser is in non-namespace-aware mode) with a base64-encoded version.static XmlNameProcessor
newPassthroughProcessor()
Generates a new processor that does nothing and just passes through the names as-is.static XmlNameProcessor
newReplacementProcessor()
Convenience method equivalent to callingnewReplacementProcessor(String)
with"_"
static XmlNameProcessor
newReplacementProcessor(java.lang.String replacement)
Generates a new processor that replaces all characters that are NOT one of: Lower- or upper-case ASCII letter (a to z, A to Z) Digit (0 to 9) in position OTHER than the first character Underscore Hyphen (-
) in position OTHER than the first character Colon (only exposed if underlying parser is in non-namespace-aware mode) in an XML name with a replacement string.
-
-
-
Method Detail
-
newPassthroughProcessor
public static XmlNameProcessor newPassthroughProcessor()
Generates a new processor that does nothing and just passes through the names as-is. Using this processor may generate invalid XML.With this processor set, a map with the keys
"123"
and"$ I am <fancy>! &;"
will be written as:<DTO> <badMap> <$ I am <fancy>! &;>xyz</$ I am <fancy>! &;> <123>bar</123> </badMap> </DTO>
This is the default behavior for backwards compatibility.
- Since:
- 2.14
-
newReplacementProcessor
public static XmlNameProcessor newReplacementProcessor(java.lang.String replacement)
Generates a new processor that replaces all characters that are NOT one of:- Lower- or upper-case ASCII letter (a to z, A to Z)
- Digit (0 to 9) in position OTHER than the first character
- Underscore
- Hyphen (
-
) in position OTHER than the first character - Colon (only exposed if underlying parser is in non-namespace-aware mode)
With this processor set (and
"_"
as the replacement string), a map with the keys"123"
and"$ I am <fancy>! &;"
will be written as:NOTE: this processor works for US-ASCII based element and attribute names but is unlikely to work well for many "international" use cases.
<DTO> <badMap> <__I_am__fancy_____>xyz</__I_am__fancy_____> <_23>bar</_23> </badMap> </DTO>
- Parameters:
replacement
- The replacement string to replace invalid characters with- Since:
- 2.14
-
newReplacementProcessor
public static XmlNameProcessor newReplacementProcessor()
Convenience method equivalent to callingnewReplacementProcessor(String)
with"_"
- Since:
- 2.14
-
newBase64Processor
public static XmlNameProcessor newBase64Processor(java.lang.String prefix)
Generates a new processor that escapes all names that contains characters OTHER than following characters:- Lower- or upper-case ASCII letter (a to z, A to Z)
- Digit (0 to 9) in position OTHER than the first characters
- Underscore
- Hyphen (
-
) in position OTHER than the first character - Colon (only exposed if underlying parser is in non-namespace-aware mode)
=
padding characters are always omitted.With this processor set, a map with the keys
"123"
and"$ I am <fancy>! &;"
will be written as:<DTO> <badMap> <base64_tag_JCBJIGFtIDxmYW5jeT4hICY7>xyz</base64_tag_JCBJIGFtIDxmYW5jeT4hICY7> <base64_tag_MTIz>bar</base64_tag_MTIz> </badMap> </DTO>
NOTE: you must ensure that no incoming element or attribute name starts with
prefix
, otherwise decoding will not work.- Parameters:
prefix
- The prefix to use for name that are escaped- Since:
- 2.14
-
newBase64Processor
public static XmlNameProcessor newBase64Processor()
Convenience method equivalent to callingnewBase64Processor(String)
with"base64_tag_"
- Since:
- 2.14
-
newAlwaysOnBase64Processor
public static XmlNameProcessor newAlwaysOnBase64Processor()
Similar tonewBase64Processor(String)
, however, names will always be escaped with base64. No magic prefix is required for this case, since adding one would be redundant because all names will be base64 encoded.
-
-