Class XmlFactory
- java.lang.Object
 - 
- com.fasterxml.jackson.core.TokenStreamFactory
 - 
- com.fasterxml.jackson.core.JsonFactory
 - 
- com.fasterxml.jackson.dataformat.xml.XmlFactory
 
 
 
 
- 
- All Implemented Interfaces:
 Versioned,java.io.Serializable
public class XmlFactory extends JsonFactory
Factory used for constructingFromXmlParserandToXmlGeneratorinstances.Implements
JsonFactorysince interface for constructing XML backed parsers and generators is quite similar to dealing with JSON.- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonFactory
JsonFactory.Feature 
 - 
 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFORMAT_NAME_XMLName 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
Constructors Constructor Description XmlFactory()Default constructor used to create factory instances.XmlFactory(ObjectCodec oc)XmlFactory(ObjectCodec oc, int xpFeatures, int xgFeatures, javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut, java.lang.String nameForTextElem)XmlFactory(ObjectCodec oc, javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut)XmlFactory(javax.xml.stream.XMLInputFactory xmlIn)XmlFactory(javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut) 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static XmlFactoryBuilderbuilder()booleancanUseCharArrays()As of 2.4, we do have actual capability for passing char arrays efficiently, but unfortunately have no working mechanism for recycling buffers.XmlFactoryconfigure(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f, boolean state)Method for enabling or disabling specified XML parser feature.XmlFactoryconfigure(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f, boolean state)Method for enabling or disabling specified XML generator feature.XmlFactorycopy()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.com.fasterxml.jackson.dataformat.xml.ser.ToXmlGeneratorcreateGenerator(java.io.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).com.fasterxml.jackson.dataformat.xml.ser.ToXmlGeneratorcreateGenerator(java.io.OutputStream out)Convenience method for constructing generator that uses default encoding of the format (UTF-8 for JSON and most other data formats).com.fasterxml.jackson.dataformat.xml.ser.ToXmlGeneratorcreateGenerator(java.io.OutputStream out, JsonEncoding enc)Method for constructing JSON generator for writing JSON content using specified output stream.com.fasterxml.jackson.dataformat.xml.ser.ToXmlGeneratorcreateGenerator(java.io.Writer out)Method for constructing JSON generator for writing JSON content using specified Writer.com.fasterxml.jackson.dataformat.xml.ser.ToXmlGeneratorcreateGenerator(javax.xml.stream.XMLStreamWriter sw)Factory method that wraps givenXMLStreamWriter, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.JsonParsercreateParser(java.lang.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.com.fasterxml.jackson.dataformat.xml.deser.FromXmlParsercreateParser(javax.xml.stream.XMLStreamReader sr)Factory method that wraps givenXMLStreamReader, usually to allow partial data-binding.XmlFactorydisable(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)Method for disabling specified XML parser feature.XmlFactorydisable(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)Method for disabling specified XML generator feature.XmlFactoryenable(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)Method for enabling specified XML parser feature.XmlFactoryenable(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)Method for enabling specified XML generator feature.intgetFormatGeneratorFeatures()java.lang.StringgetFormatName()Method that returns short textual id identifying format this factory supports.intgetFormatParserFeatures()java.lang.Class<com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature>getFormatReadFeatureType()Method for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.java.lang.Class<com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature>getFormatWriteFeatureType()Method for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.javax.xml.stream.XMLInputFactorygetXMLInputFactory()XmlNameProcessorgetXmlNameProcessor()javax.xml.stream.XMLOutputFactorygetXMLOutputFactory()java.lang.StringgetXMLTextElementName()MatchStrengthhasFormat(InputAccessor acc)static MatchStrengthhasXMLFormat(InputAccessor acc)Method that tries to figure out if content seems to be in some kind of XML format.booleanisEnabled(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)Checked whether specified XML parser feature is enabled.booleanisEnabled(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)Check whether specified XML generator feature is enabled.XmlFactoryBuilderrebuild()Method that allows construction of differently configured factory, starting with settings of this factory.booleanrequiresCustomCodec()XML format does require support from customObjectCodec(that is,XmlMapper), so need to return true here.voidsetXMLInputFactory(javax.xml.stream.XMLInputFactory f)Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor)voidsetXmlNameProcessor(XmlNameProcessor processor)voidsetXMLOutputFactory(javax.xml.stream.XMLOutputFactory f)Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor)voidsetXMLTextElementName(java.lang.String name)Versionversion()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 (seeVersionfor 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 Detail
- 
FORMAT_NAME_XML
public static final java.lang.String FORMAT_NAME_XML
Name used to identify XML format (and returned bygetFormatName()- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Constructor Detail
- 
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(ObjectCodec oc)
 
- 
XmlFactory
public XmlFactory(javax.xml.stream.XMLInputFactory xmlIn)
 
- 
XmlFactory
public XmlFactory(javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut) 
- 
XmlFactory
public XmlFactory(ObjectCodec oc, javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut)
 
- 
XmlFactory
public XmlFactory(ObjectCodec oc, int xpFeatures, int xgFeatures, javax.xml.stream.XMLInputFactory xmlIn, javax.xml.stream.XMLOutputFactory xmlOut, java.lang.String nameForTextElem)
 
 - 
 
- 
Method Detail
- 
builder
public static XmlFactoryBuilder builder()
 
- 
rebuild
public XmlFactoryBuilder rebuild()
Description copied from class:JsonFactoryMethod that allows construction of differently configured factory, starting with settings of this factory.- Overrides:
 rebuildin classJsonFactory- Returns:
 - Builder instance to use
 
 
- 
copy
public XmlFactory 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:
 copyin classJsonFactory- Returns:
 - Copy of this factory instance
 
 
- 
version
public Version version()
Description copied from interface:VersionedMethod called to detect version of the component that implements this interface; returned version should never be null, but may return specific "not available" instance (seeVersionfor details).- Specified by:
 versionin interfaceVersioned- Overrides:
 versionin classJsonFactory- Returns:
 - Version of the component
 
 
- 
setXMLTextElementName
public void setXMLTextElementName(java.lang.String name)
- Since:
 - 2.1
 
 
- 
getXMLTextElementName
public java.lang.String getXMLTextElementName()
- Since:
 - 2.2
 
 
- 
configure
public final XmlFactory configure(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f, boolean state)
Method for enabling or disabling specified XML parser feature. 
- 
enable
public XmlFactory enable(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)
Method for enabling specified XML parser feature. 
- 
disable
public XmlFactory disable(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)
Method for disabling specified XML parser feature. 
- 
isEnabled
public final boolean isEnabled(com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature f)
Checked whether specified XML parser feature is enabled. 
- 
getFormatParserFeatures
public int getFormatParserFeatures()
- Overrides:
 getFormatParserFeaturesin classJsonFactory
 
- 
getFormatGeneratorFeatures
public int getFormatGeneratorFeatures()
- Overrides:
 getFormatGeneratorFeaturesin classJsonFactory
 
- 
getXmlNameProcessor
public XmlNameProcessor getXmlNameProcessor()
 
- 
setXmlNameProcessor
public void setXmlNameProcessor(XmlNameProcessor processor)
 
- 
configure
public final XmlFactory configure(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f, boolean state)
Method for enabling or disabling specified XML generator feature. 
- 
enable
public XmlFactory enable(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)
Method for enabling specified XML generator feature. 
- 
disable
public XmlFactory disable(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)
Method for disabling specified XML generator feature. 
- 
isEnabled
public final boolean isEnabled(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature f)
Check whether specified XML generator feature is enabled. 
- 
getXMLInputFactory
public javax.xml.stream.XMLInputFactory getXMLInputFactory()
- Since:
 - 2.4
 
 
- 
setXMLInputFactory
@Deprecated public void setXMLInputFactory(javax.xml.stream.XMLInputFactory f)
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor) 
- 
getXMLOutputFactory
public javax.xml.stream.XMLOutputFactory getXMLOutputFactory()
- Since:
 - 2.4
 
 
- 
setXMLOutputFactory
@Deprecated public void setXMLOutputFactory(javax.xml.stream.XMLOutputFactory f)
Deprecated.Since 2.12 -- should be set as part of build process (either in builder, or constructor) 
- 
getFormatName
public java.lang.String 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:
 getFormatNamein classJsonFactory- Returns:
 - Name of the format handled by parsers, generators this factory creates
 
 
- 
hasFormat
public MatchStrength hasFormat(InputAccessor acc) throws java.io.IOException
- Overrides:
 hasFormatin classJsonFactory- Throws:
 java.io.IOException
 
- 
requiresCustomCodec
public boolean requiresCustomCodec()
XML format does require support from customObjectCodec(that is,XmlMapper), so need to return true here.- Overrides:
 requiresCustomCodecin 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:
 canUseCharArraysin classJsonFactory- Returns:
 - Whether access to decoded textual content can be efficiently
   accessed using parser method 
getTextCharacters(). 
 
- 
getFormatReadFeatureType
public java.lang.Class<com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature> getFormatReadFeatureType()
Description copied from class:TokenStreamFactoryMethod for accessing kind ofFormatFeaturethat a parserJsonParserproduced by this factory would accept, if any;nullreturned if none.- Overrides:
 getFormatReadFeatureTypein classJsonFactory- Returns:
 - Type of format-specific stream read features, if any; 
nullif none 
 
- 
getFormatWriteFeatureType
public java.lang.Class<com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature> getFormatWriteFeatureType()
Description copied from class:TokenStreamFactoryMethod for accessing kind ofFormatFeaturethat a parserJsonGeneratorproduced by this factory would accept, if any;nullreturned if none.- Overrides:
 getFormatWriteFeatureTypein classJsonFactory- Returns:
 - Type of format-specific stream read features, if any; 
nullif none 
 
- 
createParser
public JsonParser createParser(java.lang.String content) throws java.io.IOException
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:
 createParserin classJsonFactory- Throws:
 java.io.IOException
 
- 
createGenerator
public com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator createGenerator(java.io.OutputStream out) throws java.io.IOExceptionDescription copied from class:JsonFactoryConvenience 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:
 createGeneratorin classJsonFactory- Throws:
 java.io.IOException
 
- 
createGenerator
public com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator createGenerator(java.io.OutputStream out, JsonEncoding enc) throws java.io.IOExceptionDescription copied from class:JsonFactoryMethod 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_TARGETis 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:
 createGeneratorin classJsonFactory- Parameters:
 out- OutputStream to use for writing JSON contentenc- Character encoding to use- Throws:
 java.io.IOException
 
- 
createGenerator
public com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator createGenerator(java.io.Writer out) throws java.io.IOExceptionDescription copied from class:JsonFactoryMethod 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_TARGETis enabled). Using application needs to close it explicitly.- Overrides:
 createGeneratorin classJsonFactory- Parameters:
 out- Writer to use for writing JSON content- Throws:
 java.io.IOException
 
- 
createGenerator
public com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator createGenerator(java.io.File f, JsonEncoding enc) throws java.io.IOExceptionDescription copied from class:JsonFactoryMethod 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:
 createGeneratorin classJsonFactory- Parameters:
 f- File to write contents toenc- Character encoding to use- Throws:
 java.io.IOException
 
- 
createParser
public com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser createParser(javax.xml.stream.XMLStreamReader sr) throws java.io.IOExceptionFactory method that wraps givenXMLStreamReader, usually to allow partial data-binding.- Throws:
 java.io.IOException- Since:
 - 2.4
 
 
- 
createGenerator
public com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator createGenerator(javax.xml.stream.XMLStreamWriter sw) throws java.io.IOExceptionFactory method that wraps givenXMLStreamWriter, usually to allow incremental serialization to compose large output by serializing a sequence of individual objects.- Throws:
 java.io.IOException- Since:
 - 2.4
 
 
- 
hasXMLFormat
public static MatchStrength hasXMLFormat(InputAccessor acc) throws java.io.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:
 java.io.IOException
 
 - 
 
 -