Class FromXmlParser
java.lang.Object
com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.core.base.ParserMinimalBase
com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,ElementWrappable
,Closeable
,AutoCloseable
public class FromXmlParser
extends com.fasterxml.jackson.core.base.ParserMinimalBase
implements ElementWrappable
JsonParser
implementation that exposes XML structure as
set of JSON events that can be used for data binding.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
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
FieldsModifier and TypeFieldDescriptionprotected byte[]
We will hold on to decoded binary data, for duration of current event, so that multiple calls togetBinaryValue(com.fasterxml.jackson.core.Base64Variant)
will not need to decode data more than once.protected com.fasterxml.jackson.core.util.ByteArrayBuilder
ByteArrayBuilder is needed if 'getBinaryValue' is called.protected String
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
Flag that indicates whether parser is closed or not.protected String
protected int
Bit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled.protected final com.fasterxml.jackson.core.io.IOContext
protected boolean
We need special handling to keep track of whether a value may be exposed as simple leaf value.protected boolean
Additional flag that is strictly needed when exposing "mixed" leading String value as "anonymous" property/string pair.protected com.fasterxml.jackson.core.JsonToken
protected BigInteger
protected int
protected long
protected int
Bitfield that indicates which numeric representations have been calculated for the current typeprotected com.fasterxml.jackson.core.ObjectCodec
protected XmlReadContext
Information about parser context, context in which the next token is to be parsed (root, array, object).protected final com.fasterxml.jackson.core.StreamReadConstraints
protected final XmlTokenStream
static final String
The default name placeholder for XML text segments is empty String ("").protected static final com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability>
XML format has some peculiarities, indicated via new (2.12) capability system.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, DEFAULT_READ_CAPABILITIES
-
Constructor Summary
ConstructorsConstructorDescriptionFromXmlParser
(com.fasterxml.jackson.core.io.IOContext ctxt, int genericParserFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, XMLStreamReader xmlReader, XmlNameProcessor tagProcessor) -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
_checkNumericValue
(int expType) protected BigDecimal
protected void
protected double
protected float
protected void
protected void
protected byte[]
_decodeBase64
(com.fasterxml.jackson.core.Base64Variant b64variant) protected com.fasterxml.jackson.core.util.ByteArrayBuilder
protected void
Method called when an EOF is encountered between tokens.private <T> T
_internalErrorUnknownToken
(Object token) protected final int
_isIntNumber
(String text) protected int
protected void
Method called to release internal buffers owned by the base parser.protected void
private void
_updateState
(com.fasterxml.jackson.core.JsonToken t) void
addVirtualWrapping
(Set<String> namesToWrap0, boolean caseInsensitive) 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.boolean
boolean
void
close()
configure
(FromXmlParser.Feature f, boolean state) byte[]
getBinaryValue
(com.fasterxml.jackson.core.Base64Variant b64variant) com.fasterxml.jackson.core.ObjectCodec
getCodec()
com.fasterxml.jackson.core.JsonLocation
Method that returns location of the last processed character; usually for error reporting purposesMethod that can be called to get the name associated with the current event.double
float
int
int
long
com.fasterxml.jackson.core.JsonParser.NumberType
com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability>
Method that allows application direct access to underlying StaxXMLStreamWriter
.getText()
int
char[]
int
int
com.fasterxml.jackson.core.JsonLocation
Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.boolean
XML input actually would offer access to character arrays; but since we must coalesce things it cannot really be exposed.boolean
isClosed()
final boolean
boolean
Since xml representation can not really distinguish between different scalar types (numbers, booleans) -- they are all just Character Data, without schema -- we can try to infer type from intent here.boolean
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'.boolean
isNaN()
Method overridden to support more reliable deserialization of String collections.com.fasterxml.jackson.core.JsonToken
void
overrideCurrentName
(String name) com.fasterxml.jackson.core.JsonParser
overrideFormatFeatures
(int values, int mask) boolean
XML format does require support from customObjectCodec
(that is,XmlMapper
), so need to return true here.void
setCodec
(com.fasterxml.jackson.core.ObjectCodec c) void
setXMLTextElementName
(String name) com.fasterxml.jackson.core.StreamReadConstraints
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, _reportUnexpectedNumberChar, _throwInternal, _throwInvalidSpace, _wrapError, clearCurrentToken, currentToken, currentTokenId, getCurrentToken, getCurrentTokenId, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, 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, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _reportUnsupportedOperation, assignCurrentValue, canParseAsync, canUseSchema, configure, currentLocation, currentName, currentTokenLocation, currentValue, disable, enable, finishToken, getBinaryValue, getBooleanValue, getByteValue, getCurrentValue, getFeatureMask, getInputSource, getNonBlockingInputFeeder, getNumberValueDeferred, getNumberValueExact, getObjectId, getSchema, getShortValue, getTypeId, getValueAsBoolean, getValueAsDouble, isEnabled, isEnabled, nextBooleanValue, nextFieldName, nextFieldName, nextIntValue, nextLongValue, overrideStdFeatures, readBinaryValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, setCurrentValue, setFeatureMask, setRequestPayloadOnError, setRequestPayloadOnError, setRequestPayloadOnError, setSchema
-
Field Details
-
DEFAULT_UNNAMED_TEXT_PROPERTY
The default name placeholder for XML text segments is empty String ("").- See Also:
-
XML_READ_CAPABILITIES
protected static final com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> XML_READ_CAPABILITIESXML format has some peculiarities, indicated via new (2.12) capability system.- Since:
- 2.12
-
_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 inter-operability reasons: JAXB, for example, uses "value" as name.
- Since:
- 2.1
-
_formatFeatures
protected int _formatFeaturesBit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled. -
_objectCodec
protected com.fasterxml.jackson.core.ObjectCodec _objectCodec -
_ioContext
protected final com.fasterxml.jackson.core.io.IOContext _ioContext -
_streamReadConstraints
protected final com.fasterxml.jackson.core.StreamReadConstraints _streamReadConstraints- Since:
- 2.15
-
_closed
protected boolean _closedFlag 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. -
_parsingContext
Information about parser context, context in which the next token is to be parsed (root, array, object). -
_xmlTokens
-
_mayBeLeaf
protected boolean _mayBeLeafWe 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
-
_nextIsLeadingMixed
protected boolean _nextIsLeadingMixedAdditional flag that is strictly needed when exposing "mixed" leading String value as "anonymous" property/string pair. If so, code returns START_OBJECT first, sets_nextToken
to beFIELD_NAME
and sets this flag to indicate use of "anonymous" marker.- Since:
- 2.13
-
_byteArrayBuilder
protected com.fasterxml.jackson.core.util.ByteArrayBuilder _byteArrayBuilderByteArrayBuilder is needed if 'getBinaryValue' is called. If so, we better reuse it for remainder of content. -
_binaryValue
protected byte[] _binaryValueWe will hold on to decoded binary data, for duration of current event, so that multiple calls togetBinaryValue(com.fasterxml.jackson.core.Base64Variant)
will not need to decode data more than once. -
_numTypesValid
protected int _numTypesValidBitfield that indicates which numeric representations have been calculated for the current type -
_numberInt
protected int _numberInt -
_numberLong
protected long _numberLong -
_numberBigInt
-
-
Constructor Details
-
FromXmlParser
public FromXmlParser(com.fasterxml.jackson.core.io.IOContext ctxt, int genericParserFeatures, int xmlFeatures, com.fasterxml.jackson.core.ObjectCodec codec, XMLStreamReader xmlReader, XmlNameProcessor tagProcessor) throws IOException - Throws:
IOException
-
-
Method Details
-
version
public com.fasterxml.jackson.core.Version version()- Specified by:
version
in interfacecom.fasterxml.jackson.core.Versioned
- Specified by:
version
in classcom.fasterxml.jackson.core.JsonParser
-
getCodec
public com.fasterxml.jackson.core.ObjectCodec getCodec()- Specified by:
getCodec
in classcom.fasterxml.jackson.core.JsonParser
-
setCodec
public void setCodec(com.fasterxml.jackson.core.ObjectCodec c) - Specified by:
setCodec
in classcom.fasterxml.jackson.core.JsonParser
-
setXMLTextElementName
- Since:
- 2.1
-
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.JsonParser
- Returns:
- True since XML format does require support from codec
-
canReadObjectId
public boolean canReadObjectId()- Overrides:
canReadObjectId
in classcom.fasterxml.jackson.core.JsonParser
-
canReadTypeId
public boolean canReadTypeId()- Overrides:
canReadTypeId
in classcom.fasterxml.jackson.core.JsonParser
-
getReadCapabilities
public com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> getReadCapabilities()- Overrides:
getReadCapabilities
in classcom.fasterxml.jackson.core.JsonParser
-
enable
-
disable
-
isEnabled
-
configure
-
streamReadConstraints
public com.fasterxml.jackson.core.StreamReadConstraints streamReadConstraints()- Overrides:
streamReadConstraints
in classcom.fasterxml.jackson.core.JsonParser
-
getFormatFeatures
public int getFormatFeatures()- Overrides:
getFormatFeatures
in classcom.fasterxml.jackson.core.JsonParser
-
overrideFormatFeatures
public com.fasterxml.jackson.core.JsonParser overrideFormatFeatures(int values, int mask) - Overrides:
overrideFormatFeatures
in classcom.fasterxml.jackson.core.JsonParser
-
getStaxReader
Method that allows application direct access to underlying StaxXMLStreamWriter
. 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
Description copied from interface:ElementWrappable
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.- Specified by:
addVirtualWrapping
in interfaceElementWrappable
-
getCurrentName
Method that can be called to get the name associated with the current event.- Specified by:
getCurrentName
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
overrideCurrentName
- Specified by:
overrideCurrentName
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
isClosed
public boolean isClosed()- Specified by:
isClosed
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
-
getParsingContext
- Specified by:
getParsingContext
in classcom.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 classcom.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 classcom.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 classcom.fasterxml.jackson.core.base.ParserMinimalBase
-
isExpectedNumberIntToken
public boolean isExpectedNumberIntToken()Since xml representation can not really distinguish between different scalar types (numbers, booleans) -- they are all just Character Data, without schema -- we can try to infer type from intent here. The main benefit is avoiding checks for coercion.- Overrides:
isExpectedNumberIntToken
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
-
nextToken
- Specified by:
nextToken
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
nextTextValue
Method overridden to support more reliable deserialization of String collections.- Overrides:
nextTextValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
_updateState
private void _updateState(com.fasterxml.jackson.core.JsonToken t) -
getText
- Specified by:
getText
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
getTextCharacters
- Specified by:
getTextCharacters
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
getTextLength
- Specified by:
getTextLength
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
getTextOffset
- Specified by:
getTextOffset
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
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 classcom.fasterxml.jackson.core.base.ParserMinimalBase
-
getText
- Overrides:
getText
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getEmbeddedObject
- Overrides:
getEmbeddedObject
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getBinaryValue
public byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant b64variant) throws IOException - Specified by:
getBinaryValue
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
_decodeBase64
protected byte[] _decodeBase64(com.fasterxml.jackson.core.Base64Variant b64variant) throws IOException - Throws:
IOException
-
isNaN
public boolean isNaN()- Overrides:
isNaN
in classcom.fasterxml.jackson.core.JsonParser
-
getNumberType
- Specified by:
getNumberType
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getNumberValue
- Specified by:
getNumberValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getIntValue
- Specified by:
getIntValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getLongValue
- Specified by:
getLongValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getBigIntegerValue
- Specified by:
getBigIntegerValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getFloatValue
- Specified by:
getFloatValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getDoubleValue
- Specified by:
getDoubleValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getDecimalValue
- Specified by:
getDecimalValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
_checkNumericValue
- Throws:
IOException
-
_isIntNumber
-
_convertNumberToInt
- Throws:
IOException
-
_convertNumberToLong
- Throws:
IOException
-
_convertNumberToBigInteger
- Throws:
IOException
-
_convertNumberToFloat
- Throws:
IOException
-
_convertNumberToDouble
- Throws:
IOException
-
_convertNumberToBigDecimal
- Throws:
IOException
-
_handleEOF
protected void _handleEOF() throws com.fasterxml.jackson.core.JsonParseExceptionMethod 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 classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
com.fasterxml.jackson.core.JsonParseException
-
_releaseBuffers
Method called to release internal buffers owned by the base parser.- Throws:
IOException
-
_getByteArrayBuilder
protected com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder() -
_internalErrorUnknownToken
-
_nextToken
- Throws:
IOException
-
_skipEndElement
- Throws:
IOException
-