Class YAMLParser
java.lang.Object
com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.core.base.ParserMinimalBase
com.fasterxml.jackson.core.base.ParserBase
com.fasterxml.jackson.dataformat.yaml.YAMLParser
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,Closeable
,AutoCloseable
public class YAMLParser
extends com.fasterxml.jackson.core.base.ParserBase
JsonParser
implementation used to expose YAML documents
in form that allows other Jackson functionality to process YAML content,
such as binding POJOs to and from it, and building tree representations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration that defines all togglable features for YAML parsers.Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.core.JsonParser.NumberType, com.fasterxml.jackson.core.JsonParser.NumberTypeFP
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected String
For some tokens (specifically, numbers), we'll have cleaned up version, mostly free of underscoresprotected String
Anchor for the value that parser currently points to: in case of structured types, value whose first token current token is.protected String
Let's also have a local copy of the current field nameprotected boolean
Flag that is set when current token was derived from an Alias (reference to another value's anchor)protected int
protected org.yaml.snakeyaml.events.Event
Keep track of the last event read, to get access to Location infoprotected org.yaml.snakeyaml.events.Event
To keep track of tags ("type ids"), need to either get tags for all events, or, keep tag of relevant event that might have it: this is different from_lastEvent
in some cases.protected com.fasterxml.jackson.core.ObjectCodec
Codec used for data binding when (if) requested.protected final Reader
Need to keep track of underlyingReader
to be able to auto-close it (if required to)protected String
We need to keep track of text values.protected final org.yaml.snakeyaml.parser.ParserImpl
protected final org.yaml.snakeyaml.resolver.Resolver
Fields inherited from class com.fasterxml.jackson.core.base.ParserBase
_binaryValue, _byteArrayBuilder, _closed, _currInputProcessed, _currInputRow, _currInputRowStart, _expLength, _fractLength, _inputEnd, _inputPtr, _intLength, _ioContext, _nameCopied, _nameCopyBuffer, _nextToken, _numberBigDecimal, _numberBigInt, _numberDouble, _numberFloat, _numberInt, _numberIsNaN, _numberLong, _numberNegative, _numberString, _numTypesValid, _parsingContext, _textBuffer, _tokenInputCol, _tokenInputRow, _tokenInputTotal, JSON_READ_CAPABILITIES
Fields inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_currToken, _lastClearedToken, _streamReadConstraints, _tokenCount, _trackMaxTokenCount, 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
ConstructorsModifierConstructorDescriptionprotected
YAMLParser
(com.fasterxml.jackson.core.io.IOContext ctxt, int parserFeatures, int formatFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader, org.yaml.snakeyaml.parser.ParserImpl yamlParser) Constructor to overload by custom parser sub-classes that want to replaceParserImpl
passed.YAMLParser
(com.fasterxml.jackson.core.io.IOContext ctxt, int parserFeatures, int formatFeatures, org.yaml.snakeyaml.LoaderOptions loaderOptions, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader) YAMLParser
(com.fasterxml.jackson.core.io.IOContext ctxt, com.fasterxml.jackson.core.util.BufferRecycler br, int parserFeatures, int formatFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader) Deprecated.since 2.14, use other constructor -
Method Summary
Modifier and TypeMethodDescriptionprivate String
_cleanUnderscores
(String str, int i, int len) private com.fasterxml.jackson.core.JsonToken
_cleanYamlFloat
(String str) private com.fasterxml.jackson.core.JsonToken
_cleanYamlInt
(String str) Helper method used to clean up YAML integer value so it can be parsed using standard JDK classes.protected void
private BigInteger
_decodeBigInt
(String numStr, int base) private com.fasterxml.jackson.core.JsonToken
_decodeFromBigInteger
(BigInteger unsignedValue, boolean negative) private com.fasterxml.jackson.core.JsonToken
_decodeFromLong
(long unsignedValue, boolean negative, boolean checkIfInt) private int
_decodeInt
(String str, int base) private long
_decodeLong
(String str, int base) protected com.fasterxml.jackson.core.JsonToken
_decodeNumberIntBinary
(String value, int i, int origLen, boolean negative) protected com.fasterxml.jackson.core.JsonToken
_decodeNumberIntHex
(String value, int i, int origLen, boolean negative) protected com.fasterxml.jackson.core.JsonToken
_decodeNumberIntOctal
(String value, int i, int origLen, boolean negative) protected com.fasterxml.jackson.core.JsonToken
_decodeNumberScalar
(String value, int len) protected com.fasterxml.jackson.core.JsonToken
_decodeScalar
(org.yaml.snakeyaml.events.ScalarEvent scalar) protected com.fasterxml.jackson.core.JsonLocation
_locationFor
(org.yaml.snakeyaml.error.Mark m) protected Boolean
_matchYAMLBoolean
(String value, int len) protected int
protected void
_parseNumericValue
(int expType) private <T> T
_reportInvalidNumber
(String str, int base, Exception e) boolean
boolean
com.fasterxml.jackson.core.JsonParser
configure
(YAMLParser.Feature f, boolean state) Method for enabling or disabling specified CSV feature (checkYAMLParser.Feature
for list of features)com.fasterxml.jackson.core.JsonLocation
com.fasterxml.jackson.core.JsonLocation
com.fasterxml.jackson.core.JsonParser
Method for disabling specified CSV feature (checkYAMLParser.Feature
for list of features)com.fasterxml.jackson.core.JsonParser
Method for enabling specified CSV feature (checkYAMLParser.Feature
for list of features)com.fasterxml.jackson.core.ObjectCodec
getCodec()
Deprecated.Since 2.3 (was added in 2.1) -- usegetObjectId()
insteadcom.fasterxml.jackson.core.JsonLocation
Deprecated.Deprecated.protected org.yaml.snakeyaml.events.Event
getEvent()
Since the parserImpl cannot be replaced allow subclasses to at least be able to influence the events being consumed.int
com.fasterxml.jackson.core.JsonParser.NumberTypeFP
com.fasterxml.jackson.core.util.JacksonFeatureSet
<com.fasterxml.jackson.core.StreamReadCapability> getText()
int
char[]
int
int
com.fasterxml.jackson.core.JsonLocation
Deprecated.boolean
boolean
Method that can be used to check whether current token was created from YAML Alias token (reference to an anchor).boolean
Method for checking whether specified CSVYAMLParser.Feature
is enabled.com.fasterxml.jackson.core.JsonToken
com.fasterxml.jackson.core.JsonParser
overrideFormatFeatures
(int values, int mask) int
readBinaryValue
(com.fasterxml.jackson.core.Base64Variant b64variant, OutputStream out) boolean
void
setCodec
(com.fasterxml.jackson.core.ObjectCodec c) com.fasterxml.jackson.core.Version
version()
Methods inherited from class com.fasterxml.jackson.core.base.ParserBase
_checkStdFeatureChanges, _contentReference, _contentReferenceRedacted, _convertBigDecimalToBigInteger, _decodeBase64Escape, _decodeBase64Escape, _decodeEscaped, _eofAsNextChar, _finishString, _getBigDecimal, _getBigInteger, _getByteArrayBuilder, _getNumberDouble, _getNumberFloat, _getSourceReference, _growNameDecodeBuffer, _handleBase64MissingPadding, _handleEOF, _handleUnrecognizedCharacterEscape, _releaseBuffers, _reportMismatchedEndMarker, _reportTooLongIntegral, _throwUnquotedSpace, _validJsonTokenList, _validJsonValueList, assignCurrentValue, close, convertNumberToBigDecimal, convertNumberToBigInteger, convertNumberToDouble, convertNumberToFloat, convertNumberToInt, convertNumberToLong, createChildArrayContext, createChildObjectContext, currentValue, disable, enable, getBigIntegerValue, getBinaryValue, getDecimalValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getNumberType, getNumberValue, getNumberValueExact, getParsingContext, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, growArrayBy, isClosed, isNaN, loadMore, loadMoreGuaranteed, overrideCurrentName, overrideStdFeatures, reportInvalidBase64Char, reportInvalidBase64Char, reset, resetAsNaN, resetFloat, resetInt, setFeatureMask
Methods inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_ascii, _asciiBytes, _constructError, _currentLocationMinusOne, _decodeBase64, _getCharDesc, _hasTextualNull, _longIntegerDesc, _longNumberDesc, _nullSafeUpdateToken, _reportError, _reportError, _reportError, _reportInputCoercion, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportMissingRootWS, _reportUnexpectedChar, _reportUnexpectedNumberChar, _throwInternal, _throwInternalReturnAny, _throwInvalidSpace, _updateToken, _updateTokenToNA, _updateTokenToNull, _wrapError, clearCurrentToken, currentToken, currentTokenCount, currentTokenId, getCurrentToken, getCurrentTokenId, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, hasCurrentToken, hasToken, hasTokenId, isExpectedNumberIntToken, isExpectedStartArrayToken, isExpectedStartObjectToken, nextValue, reportInvalidNumber, reportOverflowInt, reportOverflowInt, reportOverflowInt, reportOverflowLong, reportOverflowLong, reportOverflowLong, reportUnexpectedNumberChar, skipChildren, streamReadConstraints
Methods inherited from class com.fasterxml.jackson.core.JsonParser
_codec, _constructError, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _reportUnsupportedOperation, canParseAsync, canUseSchema, configure, finishToken, getBinaryValue, getBooleanValue, getByteValue, getCurrentValue, getFeatureMask, getInputSource, getNonBlockingInputFeeder, getSchema, getShortValue, getValueAsBoolean, getValueAsDouble, isEnabled, isEnabled, nextBooleanValue, nextFieldName, nextFieldName, nextIntValue, nextLongValue, nextTextValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, setCurrentValue, setRequestPayloadOnError, setRequestPayloadOnError, setRequestPayloadOnError, setSchema
-
Field Details
-
_objectCodec
protected com.fasterxml.jackson.core.ObjectCodec _objectCodecCodec used for data binding when (if) requested. -
_formatFeatures
protected int _formatFeatures -
_cfgEmptyStringsToNull
protected boolean _cfgEmptyStringsToNull -
_reader
Need to keep track of underlyingReader
to be able to auto-close it (if required to) -
_yamlParser
protected final org.yaml.snakeyaml.parser.ParserImpl _yamlParser -
_yamlResolver
protected final org.yaml.snakeyaml.resolver.Resolver _yamlResolver -
_lastEvent
protected org.yaml.snakeyaml.events.Event _lastEventKeep track of the last event read, to get access to Location info -
_lastTagEvent
protected org.yaml.snakeyaml.events.Event _lastTagEventTo keep track of tags ("type ids"), need to either get tags for all events, or, keep tag of relevant event that might have it: this is different from_lastEvent
in some cases.- Since:
- 2.12
-
_textValue
We need to keep track of text values. -
_cleanedTextValue
For some tokens (specifically, numbers), we'll have cleaned up version, mostly free of underscores -
_currentFieldName
Let's also have a local copy of the current field name -
_currentIsAlias
protected boolean _currentIsAliasFlag that is set when current token was derived from an Alias (reference to another value's anchor)- Since:
- 2.1
-
_currentAnchor
Anchor for the value that parser currently points to: in case of structured types, value whose first token current token is.
-
-
Constructor Details
-
YAMLParser
@Deprecated public YAMLParser(com.fasterxml.jackson.core.io.IOContext ctxt, com.fasterxml.jackson.core.util.BufferRecycler br, int parserFeatures, int formatFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader) Deprecated.since 2.14, use other constructor -
YAMLParser
public YAMLParser(com.fasterxml.jackson.core.io.IOContext ctxt, int parserFeatures, int formatFeatures, org.yaml.snakeyaml.LoaderOptions loaderOptions, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader) -
YAMLParser
protected YAMLParser(com.fasterxml.jackson.core.io.IOContext ctxt, int parserFeatures, int formatFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader, org.yaml.snakeyaml.parser.ParserImpl yamlParser) Constructor to overload by custom parser sub-classes that want to replaceParserImpl
passed.- Since:
- 2.18
-
-
Method Details
-
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
-
isCurrentAlias
public boolean isCurrentAlias()Method that can be used to check whether current token was created from YAML Alias token (reference to an anchor).- Since:
- 2.1
-
getCurrentAnchor
Deprecated.Since 2.3 (was added in 2.1) -- usegetObjectId()
insteadMethod that can be used to check if the current token has an associated anchor (id to reference via Alias) -
version
public com.fasterxml.jackson.core.Version version()- Specified by:
version
in interfacecom.fasterxml.jackson.core.Versioned
- Overrides:
version
in classcom.fasterxml.jackson.core.base.ParserBase
-
requiresCustomCodec
public boolean requiresCustomCodec()- Overrides:
requiresCustomCodec
in classcom.fasterxml.jackson.core.JsonParser
-
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
-
_closeInput
- Specified by:
_closeInput
in classcom.fasterxml.jackson.core.base.ParserBase
- Throws:
IOException
-
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
-
enable
Method for enabling specified CSV feature (checkYAMLParser.Feature
for list of features) -
disable
Method for disabling specified CSV feature (checkYAMLParser.Feature
for list of features) -
configure
Method for enabling or disabling specified CSV feature (checkYAMLParser.Feature
for list of features) -
isEnabled
Method for checking whether specified CSVYAMLParser.Feature
is enabled. -
currentLocation
public com.fasterxml.jackson.core.JsonLocation currentLocation()- Overrides:
currentLocation
in classcom.fasterxml.jackson.core.JsonParser
-
currentTokenLocation
public com.fasterxml.jackson.core.JsonLocation currentTokenLocation()- Overrides:
currentTokenLocation
in classcom.fasterxml.jackson.core.JsonParser
-
getCurrentLocation
Deprecated.- Overrides:
getCurrentLocation
in classcom.fasterxml.jackson.core.base.ParserBase
-
getTokenLocation
Deprecated.- Overrides:
getTokenLocation
in classcom.fasterxml.jackson.core.base.ParserBase
-
_locationFor
protected com.fasterxml.jackson.core.JsonLocation _locationFor(org.yaml.snakeyaml.error.Mark m) -
nextToken
- Specified by:
nextToken
in classcom.fasterxml.jackson.core.base.ParserMinimalBase
- Throws:
IOException
-
getEvent
protected org.yaml.snakeyaml.events.Event getEvent()Since the parserImpl cannot be replaced allow subclasses to at least be able to influence the events being consumed. A particular use case is working around the lack of anchor and alias support to emit additional events.- Since:
- 2.18
-
_decodeScalar
protected com.fasterxml.jackson.core.JsonToken _decodeScalar(org.yaml.snakeyaml.events.ScalarEvent scalar) throws IOException - Throws:
IOException
-
_matchYAMLBoolean
-
_decodeNumberScalar
protected com.fasterxml.jackson.core.JsonToken _decodeNumberScalar(String value, int len) throws IOException - Throws:
IOException
-
_decodeNumberIntBinary
protected com.fasterxml.jackson.core.JsonToken _decodeNumberIntBinary(String value, int i, int origLen, boolean negative) throws IOException - Throws:
IOException
-
_decodeNumberIntOctal
protected com.fasterxml.jackson.core.JsonToken _decodeNumberIntOctal(String value, int i, int origLen, boolean negative) throws IOException - Throws:
IOException
-
_decodeNumberIntHex
protected com.fasterxml.jackson.core.JsonToken _decodeNumberIntHex(String value, int i, int origLen, boolean negative) throws IOException - Throws:
IOException
-
_decodeFromLong
private com.fasterxml.jackson.core.JsonToken _decodeFromLong(long unsignedValue, boolean negative, boolean checkIfInt) -
_decodeFromBigInteger
private com.fasterxml.jackson.core.JsonToken _decodeFromBigInteger(BigInteger unsignedValue, boolean negative) -
_decodeInt
- Throws:
IOException
-
_decodeLong
- Throws:
IOException
-
_decodeBigInt
- Throws:
IOException
-
_reportInvalidNumber
- Throws:
IOException
-
currentName
- Overrides:
currentName
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getCurrentName
Deprecated.- Overrides:
getCurrentName
in classcom.fasterxml.jackson.core.base.ParserBase
- Throws:
IOException
-
hasTextCharacters
public boolean hasTextCharacters()- Overrides:
hasTextCharacters
in classcom.fasterxml.jackson.core.base.ParserBase
-
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
-
getText
- Overrides:
getText
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getEmbeddedObject
- Overrides:
getEmbeddedObject
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
readBinaryValue
public int readBinaryValue(com.fasterxml.jackson.core.Base64Variant b64variant, OutputStream out) throws IOException - Overrides:
readBinaryValue
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getNumberTypeFP
- Overrides:
getNumberTypeFP
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getNumberValueDeferred
- Overrides:
getNumberValueDeferred
in classcom.fasterxml.jackson.core.base.ParserBase
- Throws:
IOException
-
_parseNumericValue
- Overrides:
_parseNumericValue
in classcom.fasterxml.jackson.core.base.ParserBase
- Throws:
IOException
-
_parseIntValue
- Overrides:
_parseIntValue
in classcom.fasterxml.jackson.core.base.ParserBase
- Throws:
IOException
-
getObjectId
- Overrides:
getObjectId
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
getTypeId
- Overrides:
getTypeId
in classcom.fasterxml.jackson.core.JsonParser
- Throws:
IOException
-
_cleanYamlInt
Helper method used to clean up YAML integer value so it can be parsed using standard JDK classes. Currently this just means stripping out optional underscores.- Throws:
IOException
-
_cleanUnderscores
-
_cleanYamlFloat
-