Class XmlFactory
java.lang.Object
com.fasterxml.jackson.core.TokenStreamFactory
com.fasterxml.jackson.core.JsonFactory
com.fasterxml.jackson.dataformat.xml.XmlFactory
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,Serializable
public class XmlFactory
extends com.fasterxml.jackson.core.JsonFactory
Factory used for constructing
FromXmlParser
and ToXmlGenerator
instances.
Implements JsonFactory
since interface for constructing XML backed
parsers and generators is quite similar to dealing with JSON.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonFactory
com.fasterxml.jackson.core.JsonFactory.Feature
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected String
Hiding place for JDK-serialization unthawed factories...protected String
Hiding place for JDK-serialization unthawed factories...protected XmlNameProcessor
protected int
protected XMLInputFactory
protected XMLOutputFactory
protected int
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
(package private) static final int
Bitfield (set of flags) of all generator features that are enabled by default.(package private) static final int
Bitfield (set of flags) of all parser features that are enabled by default.static final String
Name used to identify XML format (and returned bygetFormatName()
private static final long
private static final byte
private static final byte
private static final byte
Fields inherited from class com.fasterxml.jackson.core.JsonFactory
_byteSymbolCanonicalizer, _characterEscapes, _factoryFeatures, _generatorFeatures, _inputDecorator, _maximumNonEscapedChar, _objectCodec, _outputDecorator, _parserFeatures, _quoteChar, _rootCharSymbols, _rootValueSeparator, _streamReadConstraints, DEFAULT_FACTORY_FEATURE_FLAGS, DEFAULT_GENERATOR_FEATURE_FLAGS, DEFAULT_PARSER_FEATURE_FLAGS, DEFAULT_QUOTE_CHAR, DEFAULT_ROOT_VALUE_SEPARATOR, FORMAT_NAME_JSON
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault constructor used to create factory instances.XmlFactory
(com.fasterxml.jackson.core.ObjectCodec oc) XmlFactory
(com.fasterxml.jackson.core.ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem) protected
XmlFactory
(com.fasterxml.jackson.core.ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem, XmlNameProcessor nameProcessor) XmlFactory
(com.fasterxml.jackson.core.ObjectCodec oc, XMLInputFactory xmlIn, XMLOutputFactory xmlOut) protected
Constructors used byJsonFactoryBuilder
for instantiation.protected
XmlFactory
(XmlFactory src, com.fasterxml.jackson.core.ObjectCodec oc) XmlFactory
(XMLInputFactory xmlIn) XmlFactory
(XMLInputFactory xmlIn, XMLOutputFactory xmlOut) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.fasterxml.jackson.core.JsonGenerator
_createGenerator
(Writer out, com.fasterxml.jackson.core.io.IOContext ctxt) protected FromXmlParser
_createParser
(byte[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt) protected FromXmlParser
_createParser
(char[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt, boolean recycleBuffer) protected FromXmlParser
_createParser
(InputStream in, com.fasterxml.jackson.core.io.IOContext ctxt) protected FromXmlParser
_createParser
(Reader r, com.fasterxml.jackson.core.io.IOContext ctxt) protected XMLStreamWriter
_createXmlWriter
(com.fasterxml.jackson.core.io.IOContext ctxt, OutputStream out) protected XMLStreamWriter
_createXmlWriter
(com.fasterxml.jackson.core.io.IOContext ctxt, Writer w) protected OutputStream
_decorate
(com.fasterxml.jackson.core.io.IOContext ioCtxt, OutputStream out) protected Writer
protected void
_initFactories
(XMLInputFactory xmlIn, XMLOutputFactory xmlOut) protected final XMLStreamReader
protected final XMLStreamWriter
static XmlFactoryBuilder
builder()
boolean
As of 2.4, we do have actual capability for passing char arrays efficiently, but unfortunately have no working mechanism for recycling buffers.final XmlFactory
configure
(FromXmlParser.Feature f, boolean state) Method for enabling or disabling specified XML parser feature.final XmlFactory
configure
(ToXmlGenerator.Feature f, boolean state) Method for enabling or disabling specified XML generator feature.copy()
Note: compared to base implementation byJsonFactory
, here the copy will actually share underlying XML input and output factories, as there is no way to make copies of those.createGenerator
(File f, com.fasterxml.jackson.core.JsonEncoding enc) createGenerator
(OutputStream out, com.fasterxml.jackson.core.JsonEncoding enc) createGenerator
(Writer out) Factory method that wraps givenXMLStreamWriter
, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.com.fasterxml.jackson.core.JsonParser
createParser
(String content) Overridden just to prevent trying to optimize access via char array; while nice idea, problem is that we don't have proper hooks to ensure that temporary buffer gets recycled; so let's just use StringReader.Factory method that wraps givenXMLStreamReader
, usually to allow partial data-binding.Method for disabling specified XML parser feature.Method for disabling specified XML generator feature.Method for enabling specified XML parser feature.Method for enabling specified XML generator feature.int
Method that returns short textual id identifying format this factory supports.int
com.fasterxml.jackson.core.format.MatchStrength
hasFormat
(com.fasterxml.jackson.core.format.InputAccessor acc) static com.fasterxml.jackson.core.format.MatchStrength
hasXMLFormat
(com.fasterxml.jackson.core.format.InputAccessor acc) Method that tries to figure out if content seems to be in some kind of XML format.final boolean
Checked whether specified XML parser feature is enabled.final boolean
Check whether specified XML generator feature is enabled.private void
In addition to default serialization, which mostly works, need to handle case of XML factories, hence override.protected Object
Method that we need to override to actually make restoration go through constructors etc.rebuild()
boolean
XML format does require support from customObjectCodec
(that is,XmlMapper
), so need to return true here.void
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor)void
setXmlNameProcessor
(XmlNameProcessor processor) void
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor)void
setXMLTextElementName
(String name) private static final int
skipSpace
(com.fasterxml.jackson.core.format.InputAccessor acc, byte b) private static final com.fasterxml.jackson.core.format.MatchStrength
tryMatch
(com.fasterxml.jackson.core.format.InputAccessor acc, String matchStr, com.fasterxml.jackson.core.format.MatchStrength fullMatchStrength) private static final boolean
validXmlNameStartChar
(com.fasterxml.jackson.core.format.InputAccessor acc, byte b) com.fasterxml.jackson.core.Version
version()
private void
In addition to default serialization, which mostly works, need to handle case of XML factories, hence override.Methods inherited from class com.fasterxml.jackson.core.JsonFactory
_checkInvalidCopy, _createContentReference, _createContentReference, _createContext, _createContext, _createNonBlockingContext, _createParser, _createUTF8Generator, _createWriter, _decorate, _decorate, _decorate, _decorate, _decorate, _getBufferRecycler, canHandleBinaryNatively, canParseAsync, canUseSchema, configure, configure, configure, createGenerator, createGenerator, createJsonGenerator, createJsonGenerator, createJsonGenerator, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createJsonParser, createNonBlockingByteArrayParser, createNonBlockingByteBufferParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, createParser, disable, disable, disable, enable, enable, enable, getCharacterEscapes, getCodec, getGeneratorFeatures, getInputDecorator, getOutputDecorator, getParserFeatures, getRootValueSeparator, hasJSONFormat, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, requiresPropertyOrdering, setCharacterEscapes, setCodec, setInputDecorator, setOutputDecorator, setRootValueSeparator, setStreamReadConstraints, streamReadConstraints
Methods inherited from class com.fasterxml.jackson.core.TokenStreamFactory
_checkRangeBoundsForByteArray, _checkRangeBoundsForCharArray, _createDataOutputWrapper, _fileInputStream, _fileOutputStream, _optimizedStreamFromURL, _reportRangeError
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
FORMAT_NAME_XML
Name used to identify XML format (and returned bygetFormatName()
- See Also:
-
DEFAULT_XML_PARSER_FEATURE_FLAGS
static final int DEFAULT_XML_PARSER_FEATURE_FLAGSBitfield (set of flags) of all parser features that are enabled by default. -
DEFAULT_XML_GENERATOR_FEATURE_FLAGS
static final int DEFAULT_XML_GENERATOR_FEATURE_FLAGSBitfield (set of flags) of all generator features that are enabled by default. -
_xmlParserFeatures
protected int _xmlParserFeatures -
_xmlGeneratorFeatures
protected int _xmlGeneratorFeatures -
_xmlInputFactory
-
_xmlOutputFactory
-
_cfgNameForTextElement
-
_nameProcessor
-
_jdkXmlInFactory
Hiding place for JDK-serialization unthawed factories... -
_jdkXmlOutFactory
Hiding place for JDK-serialization unthawed factories... -
UTF8_BOM_1
private static final byte UTF8_BOM_1- See Also:
-
UTF8_BOM_2
private static final byte UTF8_BOM_2- See Also:
-
UTF8_BOM_3
private static final byte UTF8_BOM_3- See Also:
-
BYTE_x
private static final byte BYTE_x- See Also:
-
BYTE_m
private static final byte BYTE_m- See Also:
-
BYTE_l
private static final byte BYTE_l- See Also:
-
BYTE_D
private static final byte BYTE_D- See Also:
-
BYTE_LT
private static final byte BYTE_LT- See Also:
-
BYTE_QMARK
private static final byte BYTE_QMARK- See Also:
-
BYTE_EXCL
private static final byte BYTE_EXCL- See Also:
-
BYTE_HYPHEN
private static final byte BYTE_HYPHEN- See Also:
-
-
Constructor Details
-
XmlFactory
public XmlFactory()Default constructor used to create factory instances. Creation of a factory instance is a light-weight operation, but it is still a good idea to reuse limited number of factory instances (and quite often just a single instance): factories are used as context for storing some reused processing objects (such as symbol tables parsers use) and this reuse only works within context of a single factory instance. -
XmlFactory
public XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc) -
XmlFactory
-
XmlFactory
-
XmlFactory
public XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc, XMLInputFactory xmlIn, XMLOutputFactory xmlOut) -
XmlFactory
public XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem) -
XmlFactory
protected XmlFactory(com.fasterxml.jackson.core.ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem, XmlNameProcessor nameProcessor) -
XmlFactory
- Since:
- 2.2.1
-
XmlFactory
Constructors used byJsonFactoryBuilder
for instantiation.- Since:
- 2.9
-
-
Method Details
-
builder
-
rebuild
- Overrides:
rebuild
in classcom.fasterxml.jackson.core.JsonFactory
-
_initFactories
-
copy
Note: compared to base implementation byJsonFactory
, here the copy will actually share underlying XML input and output factories, as there is no way to make copies of those.- Overrides:
copy
in classcom.fasterxml.jackson.core.JsonFactory
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
version
in interfacecom.fasterxml.jackson.core.Versioned
- Overrides:
version
in classcom.fasterxml.jackson.core.JsonFactory
-
readResolve
Method that we need to override to actually make restoration go through constructors etc.- Overrides:
readResolve
in classcom.fasterxml.jackson.core.JsonFactory
-
readObject
In addition to default serialization, which mostly works, need to handle case of XML factories, hence override.- Throws:
IOException
ClassNotFoundException
-
writeObject
In addition to default serialization, which mostly works, need to handle case of XML factories, hence override.- Throws:
IOException
-
setXMLTextElementName
- Since:
- 2.1
-
getXMLTextElementName
- Since:
- 2.2
-
configure
Method for enabling or disabling specified XML parser feature. -
enable
Method for enabling specified XML parser feature. -
disable
Method for disabling specified XML parser feature. -
isEnabled
Checked whether specified XML parser feature is enabled. -
getFormatParserFeatures
public int getFormatParserFeatures()- Overrides:
getFormatParserFeatures
in classcom.fasterxml.jackson.core.JsonFactory
-
getFormatGeneratorFeatures
public int getFormatGeneratorFeatures()- Overrides:
getFormatGeneratorFeatures
in classcom.fasterxml.jackson.core.JsonFactory
-
getXmlNameProcessor
-
setXmlNameProcessor
-
configure
Method for enabling or disabling specified XML generator feature. -
enable
Method for enabling specified XML generator feature. -
disable
Method for disabling specified XML generator feature. -
isEnabled
Check whether specified XML generator feature is enabled. -
getXMLInputFactory
- Since:
- 2.4
-
setXMLInputFactory
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor) -
getXMLOutputFactory
- Since:
- 2.4
-
setXMLOutputFactory
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor) -
getFormatName
Method that returns short textual id identifying format this factory supports.Note: sub-classes should override this method; default implementation will return null for all sub-classes
- Overrides:
getFormatName
in classcom.fasterxml.jackson.core.JsonFactory
-
hasFormat
public com.fasterxml.jackson.core.format.MatchStrength hasFormat(com.fasterxml.jackson.core.format.InputAccessor acc) throws IOException - Overrides:
hasFormat
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
requiresCustomCodec
public boolean requiresCustomCodec()XML format does require support from customObjectCodec
(that is,XmlMapper
), so need to return true here.- Overrides:
requiresCustomCodec
in classcom.fasterxml.jackson.core.JsonFactory
- Returns:
- True since XML format does require support from codec
-
canUseCharArrays
public boolean canUseCharArrays()As of 2.4, we do have actual capability for passing char arrays efficiently, but unfortunately have no working mechanism for recycling buffers. So we have to admit that can not make efficient use.- Overrides:
canUseCharArrays
in classcom.fasterxml.jackson.core.JsonFactory
-
getFormatReadFeatureType
- Overrides:
getFormatReadFeatureType
in classcom.fasterxml.jackson.core.JsonFactory
-
getFormatWriteFeatureType
- Overrides:
getFormatWriteFeatureType
in classcom.fasterxml.jackson.core.JsonFactory
-
createParser
Overridden just to prevent trying to optimize access via char array; while nice idea, problem is that we don't have proper hooks to ensure that temporary buffer gets recycled; so let's just use StringReader.- Overrides:
createParser
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
createGenerator
- Overrides:
createGenerator
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
createGenerator
public ToXmlGenerator createGenerator(OutputStream out, com.fasterxml.jackson.core.JsonEncoding enc) throws IOException - Overrides:
createGenerator
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
createGenerator
- Overrides:
createGenerator
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
createGenerator
public ToXmlGenerator createGenerator(File f, com.fasterxml.jackson.core.JsonEncoding enc) throws IOException - Overrides:
createGenerator
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
createParser
Factory method that wraps givenXMLStreamReader
, usually to allow partial data-binding.- Throws:
IOException
- Since:
- 2.4
-
createGenerator
Factory method that wraps givenXMLStreamWriter
, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.- Throws:
IOException
- Since:
- 2.4
-
_createParser
protected FromXmlParser _createParser(InputStream in, com.fasterxml.jackson.core.io.IOContext ctxt) throws IOException - Overrides:
_createParser
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
_createParser
protected FromXmlParser _createParser(Reader r, com.fasterxml.jackson.core.io.IOContext ctxt) throws IOException - Overrides:
_createParser
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
_createParser
protected FromXmlParser _createParser(char[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt, boolean recycleBuffer) throws IOException - Overrides:
_createParser
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
_createParser
protected FromXmlParser _createParser(byte[] data, int offset, int len, com.fasterxml.jackson.core.io.IOContext ctxt) throws IOException - Overrides:
_createParser
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
_createGenerator
protected com.fasterxml.jackson.core.JsonGenerator _createGenerator(Writer out, com.fasterxml.jackson.core.io.IOContext ctxt) throws IOException - Overrides:
_createGenerator
in classcom.fasterxml.jackson.core.JsonFactory
- Throws:
IOException
-
_createXmlWriter
protected XMLStreamWriter _createXmlWriter(com.fasterxml.jackson.core.io.IOContext ctxt, OutputStream out) throws IOException - Throws:
IOException
-
_createXmlWriter
protected XMLStreamWriter _createXmlWriter(com.fasterxml.jackson.core.io.IOContext ctxt, Writer w) throws IOException - Throws:
IOException
-
_initializeXmlWriter
- Throws:
IOException
-
_initializeXmlReader
- Throws:
IOException
-
hasXMLFormat
public static com.fasterxml.jackson.core.format.MatchStrength hasXMLFormat(com.fasterxml.jackson.core.format.InputAccessor acc) throws IOException Method that tries to figure out if content seems to be in some kind of XML format. Note that implementation here is not nearly as robust as what underlying Stax parser will do; the idea is to first support common encodings, then expand as needed (for example, it is not all that hard to support UTF-16; but it is some work and not needed quite yet)- Throws:
IOException
-
validXmlNameStartChar
private static final boolean validXmlNameStartChar(com.fasterxml.jackson.core.format.InputAccessor acc, byte b) throws IOException - Throws:
IOException
-
tryMatch
private static final com.fasterxml.jackson.core.format.MatchStrength tryMatch(com.fasterxml.jackson.core.format.InputAccessor acc, String matchStr, com.fasterxml.jackson.core.format.MatchStrength fullMatchStrength) throws IOException - Throws:
IOException
-
skipSpace
private static final int skipSpace(com.fasterxml.jackson.core.format.InputAccessor acc, byte b) throws IOException - Throws:
IOException
-
_decorate
protected OutputStream _decorate(com.fasterxml.jackson.core.io.IOContext ioCtxt, OutputStream out) throws IOException - Throws:
IOException
-
_decorate
protected Writer _decorate(com.fasterxml.jackson.core.io.IOContext ioCtxt, Writer out) throws IOException - Throws:
IOException
-