Class XmlFactory
- All Implemented Interfaces:
Versioned
,Serializable
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
JsonFactory.Feature
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name used to identify XML format (and returned bygetFormatName()
Fields inherited from class com.fasterxml.jackson.core.JsonFactory
DEFAULT_QUOTE_CHAR, DEFAULT_ROOT_VALUE_SEPARATOR, FORMAT_NAME_JSON
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor used to create factory instances.XmlFactory
(ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem) XmlFactory
(ObjectCodec oc, XMLInputFactory xmlIn, XMLOutputFactory xmlOut) XmlFactory
(XMLInputFactory xmlIn) XmlFactory
(XMLInputFactory xmlIn, XMLOutputFactory xmlOut) -
Method Summary
Modifier and TypeMethodDescriptionstatic 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, JsonEncoding enc) Method for constructing JSON generator for writing JSON content to specified file, overwriting contents it might have (or creating it if such file does not yet exist).Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).createGenerator
(OutputStream out, JsonEncoding enc) Method for constructing JSON generator for writing JSON content using specified output stream.createGenerator
(Writer out) Method for constructing JSON generator for writing JSON content using specified Writer.Factory method that wraps givenXMLStreamWriter
, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.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
Method for accessing kind ofFormatFeature
that a parserJsonParser
produced by this factory would accept, if any;null
returned if none.Method for accessing kind ofFormatFeature
that a parserJsonGenerator
produced by this factory would accept, if any;null
returned if none.hasFormat
(InputAccessor acc) static MatchStrength
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.rebuild()
Method that allows construction of differently configured factory, starting with settings of this factory.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) version()
Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersion
for details).Methods inherited from class com.fasterxml.jackson.core.JsonFactory
_getBufferRecycler, _getRecyclerPool, 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, getFactoryFeatures, getGeneratorFeatures, getInputDecorator, getOutputDecorator, getParserFeatures, getRootValueSeparator, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, requiresPropertyOrdering, setCharacterEscapes, setCodec, setErrorReportConfiguration, setInputDecorator, setOutputDecorator, setRecyclerPool, setRootValueSeparator, setStreamReadConstraints, setStreamWriteConstraints, streamReadConstraints, streamWriteConstraints
-
Field Details
-
FORMAT_NAME_XML
Name used to identify XML format (and returned bygetFormatName()
- 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
-
XmlFactory
-
XmlFactory
-
XmlFactory
-
XmlFactory
public XmlFactory(ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem)
-
-
Method Details
-
builder
-
rebuild
Description copied from class:JsonFactory
Method that allows construction of differently configured factory, starting with settings of this factory.- Overrides:
rebuild
in classJsonFactory
- Returns:
- Builder instance to use
-
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 classJsonFactory
- Returns:
- Copy of this factory instance
-
version
Description copied from interface:Versioned
Method called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersion
for details).- Specified by:
version
in interfaceVersioned
- Overrides:
version
in classJsonFactory
- Returns:
- Version of the component
-
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 classJsonFactory
-
getFormatGeneratorFeatures
public int getFormatGeneratorFeatures()- Overrides:
getFormatGeneratorFeatures
in classJsonFactory
-
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 classJsonFactory
- Returns:
- Name of the format handled by parsers, generators this factory creates
-
hasFormat
- Overrides:
hasFormat
in classJsonFactory
- 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 classJsonFactory
- 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 classJsonFactory
- Returns:
- Whether access to decoded textual content can be efficiently
accessed using parser method
getTextCharacters()
.
-
getFormatReadFeatureType
Description copied from class:TokenStreamFactory
Method for accessing kind ofFormatFeature
that a parserJsonParser
produced by this factory would accept, if any;null
returned if none.- Overrides:
getFormatReadFeatureType
in classJsonFactory
- Returns:
- Type of format-specific stream read features, if any;
null
if none
-
getFormatWriteFeatureType
Description copied from class:TokenStreamFactory
Method for accessing kind ofFormatFeature
that a parserJsonGenerator
produced by this factory would accept, if any;null
returned if none.- Overrides:
getFormatWriteFeatureType
in classJsonFactory
- Returns:
- Type of format-specific stream read features, if any;
null
if none
-
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 classJsonFactory
- Throws:
IOException
-
createGenerator
Description copied from class:JsonFactory
Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).Note: there are formats that use fixed encoding (like most binary data formats).
- Overrides:
createGenerator
in classJsonFactory
- Throws:
IOException
-
createGenerator
Description copied from class:JsonFactory
Method for constructing JSON generator for writing JSON content using specified output stream. Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the output stream when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly if this is the case.Note: there are formats that use fixed encoding (like most binary data formats) and that ignore passed in encoding.
- Overrides:
createGenerator
in classJsonFactory
- Parameters:
out
- OutputStream to use for writing JSON contentenc
- Character encoding to use- Throws:
IOException
-
createGenerator
Description copied from class:JsonFactory
Method for constructing JSON generator for writing JSON content using specified Writer.Underlying stream is NOT owned by the generator constructed, so that generator will NOT close the Reader when
JsonGenerator.close()
is called (unless auto-closing feature,JsonGenerator.Feature.AUTO_CLOSE_TARGET
is enabled). Using application needs to close it explicitly.- Overrides:
createGenerator
in classJsonFactory
- Parameters:
out
- Writer to use for writing JSON content- Throws:
IOException
-
createGenerator
Description copied from class:JsonFactory
Method for constructing JSON generator for writing JSON content to specified file, overwriting contents it might have (or creating it if such file does not yet exist). Encoding to use must be specified, and needs to be one of available types (as per JSON specification).Underlying stream is owned by the generator constructed, i.e. generator will handle closing of file when
JsonGenerator.close()
is called.- Overrides:
createGenerator
in classJsonFactory
- Parameters:
f
- File to write contents toenc
- Character encoding to use- 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
-
hasXMLFormat
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
-