Class FromXmlParser

  • All Implemented Interfaces:
    com.fasterxml.jackson.core.Versioned, java.io.Closeable, java.lang.AutoCloseable

    public class FromXmlParser
    extends com.fasterxml.jackson.core.base.ParserMinimalBase
    JsonParser implementation that exposes XML structure as set of JSON events that can be used for data binding.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FromXmlParser.Feature
      Enumeration that defines all togglable features for XML parsers.
      • Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonParser

        com.fasterxml.jackson.core.JsonParser.NumberType
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] _binaryValue
      We will hold on to decoded binary data, for duration of current event, so that multiple calls to getBinaryValue(com.fasterxml.jackson.core.Base64Variant) will not need to decode data more than once.
      protected com.fasterxml.jackson.core.util.ByteArrayBuilder _byteArrayBuilder
      ByteArrayBuilder is needed if 'getBinaryValue' is called.
      protected java.lang.String _cfgNameForTextElement
      In cases where a start element has both attributes and non-empty textual value, we have to create a bogus property; we will use this as the property name.
      protected boolean _closed
      Flag that indicates whether parser is closed or not.
      protected java.lang.String _currText  
      protected int _formatFeatures
      Bit flag composed of bits that indicate which FromXmlParser.Features are enabled.
      protected com.fasterxml.jackson.core.io.IOContext _ioContext  
      protected boolean _mayBeLeaf
      We need special handling to keep track of whether a value may be exposed as simple leaf value.
      protected java.util.Set<java.lang.String> _namesToWrap  
      protected com.fasterxml.jackson.core.JsonToken _nextToken  
      protected com.fasterxml.jackson.core.ObjectCodec _objectCodec  
      protected XmlReadContext _parsingContext
      Information about parser context, context in which the next token is to be parsed (root, array, object).
      protected XmlTokenStream _xmlTokens  
      static java.lang.String DEFAULT_UNNAMED_TEXT_PROPERTY
      The default name placeholder for XML text segments is empty String ("").
      • Fields inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase

        _currToken, _lastClearedToken, BD_MAX_INT, BD_MAX_LONG, BD_MIN_INT, BD_MIN_LONG, BI_MAX_INT, BI_MAX_LONG, BI_MIN_INT, BI_MIN_LONG, CHAR_NULL, INT_0, INT_9, INT_APOS, INT_ASTERISK, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_e, INT_E, INT_HASH, INT_LBRACKET, INT_LCURLY, INT_LF, INT_MINUS, INT_PERIOD, INT_PLUS, INT_QUOTE, INT_RBRACKET, INT_RCURLY, INT_SLASH, INT_SPACE, INT_TAB, MAX_ERROR_TOKEN_LENGTH, MAX_INT_D, MAX_INT_L, MAX_LONG_D, MIN_INT_D, MIN_INT_L, MIN_LONG_D, NO_BYTES, NO_INTS, NR_BIGDECIMAL, NR_BIGINT, NR_DOUBLE, NR_FLOAT, NR_INT, NR_LONG, NR_UNKNOWN
      • Fields inherited from class com.fasterxml.jackson.core.JsonParser

        _features, _requestPayload
    • Constructor Summary

      Constructors 
      Constructor Description
      FromXmlParser​(com.fasterxml.jackson.core.io.IOContext ctxt, int genericParserFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, javax.xml.stream.XMLStreamReader xmlReader)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected byte[] _decodeBase64​(com.fasterxml.jackson.core.Base64Variant b64variant)  
      protected com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()  
      protected void _handleEOF()
      Method called when an EOF is encountered between tokens.
      protected boolean _isEmpty​(java.lang.String str)  
      protected void _releaseBuffers()
      Method called to release internal buffers owned by the base parser.
      void addVirtualWrapping​(java.util.Set<java.lang.String> namesToWrap)
      Method that may be called to indicate that specified names (only local parts retained currently: this may be changed in future) should be considered "auto-wrapping", meaning that they will be doubled to contain two opening elements, two matching closing elements.
      void close()  
      FromXmlParser configure​(FromXmlParser.Feature f, boolean state)  
      FromXmlParser disable​(FromXmlParser.Feature f)  
      FromXmlParser enable​(FromXmlParser.Feature f)  
      java.math.BigInteger getBigIntegerValue()  
      byte[] getBinaryValue​(com.fasterxml.jackson.core.Base64Variant b64variant)  
      com.fasterxml.jackson.core.ObjectCodec getCodec()  
      com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
      Method that returns location of the last processed character; usually for error reporting purposes
      java.lang.String getCurrentName()
      Method that can be called to get the name associated with the current event.
      java.math.BigDecimal getDecimalValue()  
      double getDoubleValue()  
      java.lang.Object getEmbeddedObject()  
      float getFloatValue()  
      int getFormatFeatures()  
      int getIntValue()  
      long getLongValue()  
      com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()  
      java.lang.Number getNumberValue()  
      XmlReadContext getParsingContext()  
      javax.xml.stream.XMLStreamReader getStaxReader()
      Method that allows application direct access to underlying Stax XMLStreamWriter.
      java.lang.String getText()  
      int getText​(java.io.Writer writer)  
      char[] getTextCharacters()  
      int getTextLength()  
      int getTextOffset()  
      com.fasterxml.jackson.core.JsonLocation getTokenLocation()
      Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.
      java.lang.String getValueAsString()  
      java.lang.String getValueAsString​(java.lang.String defValue)  
      boolean hasTextCharacters()
      XML input actually would offer access to character arrays; but since we must coalesce things it cannot really be exposed.
      boolean isClosed()  
      boolean isEnabled​(FromXmlParser.Feature f)  
      boolean isExpectedStartArrayToken()
      Since xml representation can not really distinguish between array and object starts (both are represented with elements), this method is overridden and taken to mean that expecation is that the current start element is to mean 'start array', instead of default of 'start object'.
      java.lang.String nextTextValue()
      Method overridden to support more reliable deserialization of String collections.
      com.fasterxml.jackson.core.JsonToken nextToken()  
      void overrideCurrentName​(java.lang.String name)  
      com.fasterxml.jackson.core.JsonParser overrideFormatFeatures​(int values, int mask)  
      boolean requiresCustomCodec()
      XML format does require support from custom ObjectCodec (that is, XmlMapper), so need to return true here.
      void setCodec​(com.fasterxml.jackson.core.ObjectCodec c)  
      void setXMLTextElementName​(java.lang.String name)  
      com.fasterxml.jackson.core.Version version()  
      • Methods inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase

        _ascii, _asciiBytes, _constructError, _decodeBase64, _getCharDesc, _hasTextualNull, _longIntegerDesc, _longNumberDesc, _reportError, _reportError, _reportError, _reportInputCoercion, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportInvalidEOFInValue, _reportMissingRootWS, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _wrapError, clearCurrentToken, currentToken, currentTokenId, getCurrentToken, getCurrentTokenId, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, hasCurrentToken, hasToken, hasTokenId, isExpectedStartObjectToken, nextValue, reportInvalidNumber, reportOverflowInt, reportOverflowInt, reportOverflowInt, reportOverflowLong, reportOverflowLong, reportOverflowLong, reportUnexpectedNumberChar, skipChildren
      • Methods inherited from class com.fasterxml.jackson.core.JsonParser

        _codec, _constructError, _reportUnsupportedOperation, canParseAsync, canReadObjectId, canReadTypeId, canUseSchema, configure, currentName, disable, enable, finishToken, getBinaryValue, getBooleanValue, getByteValue, getCurrentValue, getFeatureMask, getInputSource, getNonBlockingInputFeeder, getObjectId, getSchema, getShortValue, getTypeId, getValueAsBoolean, getValueAsDouble, isEnabled, isEnabled, isNaN, nextBooleanValue, nextFieldName, nextFieldName, nextIntValue, nextLongValue, overrideStdFeatures, readBinaryValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, setCurrentValue, setFeatureMask, setRequestPayloadOnError, setRequestPayloadOnError, setRequestPayloadOnError, setSchema
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_UNNAMED_TEXT_PROPERTY

        public static final java.lang.String DEFAULT_UNNAMED_TEXT_PROPERTY
        The default name placeholder for XML text segments is empty String ("").
        See Also:
        Constant Field Values
      • _cfgNameForTextElement

        protected java.lang.String _cfgNameForTextElement
        In cases where a start element has both attributes and non-empty textual value, we have to create a bogus property; we will use this as the property name.

        Name used for pseudo-property used for returning XML Text value (which does not have actual element name to use). Defaults to empty String, but may be changed for interoperability reasons: JAXB, for example, uses "value" as name.

        Since:
        2.1
      • _formatFeatures

        protected int _formatFeatures
        Bit flag composed of bits that indicate which FromXmlParser.Features are enabled.
      • _objectCodec

        protected com.fasterxml.jackson.core.ObjectCodec _objectCodec
      • _closed

        protected boolean _closed
        Flag that indicates whether parser is closed or not. Gets set when parser is either closed by explicit call (close()) or when end-of-input is reached.
      • _ioContext

        protected final com.fasterxml.jackson.core.io.IOContext _ioContext
      • _parsingContext

        protected XmlReadContext _parsingContext
        Information about parser context, context in which the next token is to be parsed (root, array, object).
      • _mayBeLeaf

        protected boolean _mayBeLeaf
        We need special handling to keep track of whether a value may be exposed as simple leaf value.
      • _nextToken

        protected com.fasterxml.jackson.core.JsonToken _nextToken
      • _currText

        protected java.lang.String _currText
      • _namesToWrap

        protected java.util.Set<java.lang.String> _namesToWrap
      • _byteArrayBuilder

        protected com.fasterxml.jackson.core.util.ByteArrayBuilder _byteArrayBuilder
        ByteArrayBuilder is needed if 'getBinaryValue' is called. If so, we better reuse it for remainder of content.
    • Constructor Detail

      • FromXmlParser

        public FromXmlParser​(com.fasterxml.jackson.core.io.IOContext ctxt,
                             int genericParserFeatures,
                             int xmlFeatures,
                             com.fasterxml.jackson.core.ObjectCodec codec,
                             javax.xml.stream.XMLStreamReader xmlReader)
                      throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • version

        public com.fasterxml.jackson.core.Version version()
        Specified by:
        version in interface com.fasterxml.jackson.core.Versioned
        Specified by:
        version in class com.fasterxml.jackson.core.JsonParser
      • getCodec

        public com.fasterxml.jackson.core.ObjectCodec getCodec()
        Specified by:
        getCodec in class com.fasterxml.jackson.core.JsonParser
      • setCodec

        public void setCodec​(com.fasterxml.jackson.core.ObjectCodec c)
        Specified by:
        setCodec in class com.fasterxml.jackson.core.JsonParser
      • setXMLTextElementName

        public void setXMLTextElementName​(java.lang.String name)
        Since:
        2.1
      • requiresCustomCodec

        public boolean requiresCustomCodec()
        XML format does require support from custom ObjectCodec (that is, XmlMapper), so need to return true here.
        Overrides:
        requiresCustomCodec in class com.fasterxml.jackson.core.JsonParser
        Returns:
        True since XML format does require support from codec
      • getFormatFeatures

        public int getFormatFeatures()
        Overrides:
        getFormatFeatures in class com.fasterxml.jackson.core.JsonParser
      • overrideFormatFeatures

        public com.fasterxml.jackson.core.JsonParser overrideFormatFeatures​(int values,
                                                                            int mask)
        Overrides:
        overrideFormatFeatures in class com.fasterxml.jackson.core.JsonParser
      • getStaxReader

        public javax.xml.stream.XMLStreamReader getStaxReader()
        Method that allows application direct access to underlying Stax XMLStreamWriter. Note that use of writer is discouraged, and may interfere with processing of this writer; however, occasionally it may be necessary.

        Note: writer instance will always be of type XMLStreamWriter2 (including Typed Access API) so upcasts are safe.

      • addVirtualWrapping

        public void addVirtualWrapping​(java.util.Set<java.lang.String> namesToWrap)
        Method that may be called to indicate that specified names (only local parts retained currently: this may be changed in future) should be considered "auto-wrapping", meaning that they will be doubled to contain two opening elements, two matching closing elements. This is needed for supporting handling of so-called "unwrapped" array types, something XML mappings like JAXB often use.

        NOTE: this method is considered part of internal implementation interface, and it is NOT guaranteed to remain unchanged between minor versions (it is however expected not to change in patch versions). So if you have to use it, be prepared for possible additional work.

        Since:
        2.1
      • getCurrentName

        public java.lang.String getCurrentName()
                                        throws java.io.IOException
        Method that can be called to get the name associated with the current event.
        Specified by:
        getCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • overrideCurrentName

        public void overrideCurrentName​(java.lang.String name)
        Specified by:
        overrideCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBase
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in class com.fasterxml.jackson.core.base.ParserMinimalBase
      • getParsingContext

        public XmlReadContext getParsingContext()
        Specified by:
        getParsingContext in class com.fasterxml.jackson.core.base.ParserMinimalBase
      • getTokenLocation

        public com.fasterxml.jackson.core.JsonLocation getTokenLocation()
        Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.
        Specified by:
        getTokenLocation in class com.fasterxml.jackson.core.JsonParser
      • getCurrentLocation

        public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
        Method that returns location of the last processed character; usually for error reporting purposes
        Specified by:
        getCurrentLocation in class com.fasterxml.jackson.core.JsonParser
      • isExpectedStartArrayToken

        public boolean isExpectedStartArrayToken()
        Since xml representation can not really distinguish between array and object starts (both are represented with elements), this method is overridden and taken to mean that expecation is that the current start element is to mean 'start array', instead of default of 'start object'.
        Overrides:
        isExpectedStartArrayToken in class com.fasterxml.jackson.core.base.ParserMinimalBase
      • nextToken

        public com.fasterxml.jackson.core.JsonToken nextToken()
                                                       throws java.io.IOException
        Specified by:
        nextToken in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • nextTextValue

        public java.lang.String nextTextValue()
                                       throws java.io.IOException
        Method overridden to support more reliable deserialization of String collections.
        Overrides:
        nextTextValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getText

        public java.lang.String getText()
                                 throws java.io.IOException
        Specified by:
        getText in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • getValueAsString

        public final java.lang.String getValueAsString()
                                                throws java.io.IOException
        Overrides:
        getValueAsString in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • getValueAsString

        public java.lang.String getValueAsString​(java.lang.String defValue)
                                          throws java.io.IOException
        Overrides:
        getValueAsString in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • getTextCharacters

        public char[] getTextCharacters()
                                 throws java.io.IOException
        Specified by:
        getTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • getTextLength

        public int getTextLength()
                          throws java.io.IOException
        Specified by:
        getTextLength in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • getTextOffset

        public int getTextOffset()
                          throws java.io.IOException
        Specified by:
        getTextOffset in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • hasTextCharacters

        public boolean hasTextCharacters()
        XML input actually would offer access to character arrays; but since we must coalesce things it cannot really be exposed.
        Specified by:
        hasTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBase
      • getText

        public int getText​(java.io.Writer writer)
                    throws java.io.IOException
        Overrides:
        getText in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getEmbeddedObject

        public java.lang.Object getEmbeddedObject()
                                           throws java.io.IOException
        Overrides:
        getEmbeddedObject in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getBinaryValue

        public byte[] getBinaryValue​(com.fasterxml.jackson.core.Base64Variant b64variant)
                              throws java.io.IOException
        Specified by:
        getBinaryValue in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        java.io.IOException
      • _decodeBase64

        protected byte[] _decodeBase64​(com.fasterxml.jackson.core.Base64Variant b64variant)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getBigIntegerValue

        public java.math.BigInteger getBigIntegerValue()
                                                throws java.io.IOException
        Specified by:
        getBigIntegerValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getDecimalValue

        public java.math.BigDecimal getDecimalValue()
                                             throws java.io.IOException
        Specified by:
        getDecimalValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getDoubleValue

        public double getDoubleValue()
                              throws java.io.IOException
        Specified by:
        getDoubleValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getFloatValue

        public float getFloatValue()
                            throws java.io.IOException
        Specified by:
        getFloatValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getIntValue

        public int getIntValue()
                        throws java.io.IOException
        Specified by:
        getIntValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getLongValue

        public long getLongValue()
                          throws java.io.IOException
        Specified by:
        getLongValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getNumberType

        public com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
                                                                       throws java.io.IOException
        Specified by:
        getNumberType in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • getNumberValue

        public java.lang.Number getNumberValue()
                                        throws java.io.IOException
        Specified by:
        getNumberValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • _handleEOF

        protected void _handleEOF()
                           throws com.fasterxml.jackson.core.JsonParseException
        Method called when an EOF is encountered between tokens. If so, it may be a legitimate EOF, but only iff there is no open non-root context.
        Specified by:
        _handleEOF in class com.fasterxml.jackson.core.base.ParserMinimalBase
        Throws:
        com.fasterxml.jackson.core.JsonParseException
      • _releaseBuffers

        protected void _releaseBuffers()
                                throws java.io.IOException
        Method called to release internal buffers owned by the base parser.
        Throws:
        java.io.IOException
      • _getByteArrayBuilder

        protected com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()
      • _isEmpty

        protected boolean _isEmpty​(java.lang.String str)