Class YAMLParser

  • All Implemented Interfaces:
    com.fasterxml.jackson.core.Versioned, java.io.Closeable, java.lang.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 Classes 
      Modifier and Type Class Description
      static class  YAMLParser.Feature
      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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String _cleanedTextValue
      For some tokens (specifically, numbers), we'll have cleaned up version, mostly free of underscores
      protected java.lang.String _currentAnchor
      Anchor for the value that parser currently points to: in case of structured types, value whose first token current token is.
      protected java.lang.String _currentFieldName
      Let's also have a local copy of the current field name
      protected boolean _currentIsAlias
      Flag that is set when current token was derived from an Alias (reference to another value's anchor)
      protected int _formatFeatures  
      protected org.yaml.snakeyaml.events.Event _lastEvent
      Keep track of the last event read, to get access to Location info
      protected com.fasterxml.jackson.core.ObjectCodec _objectCodec
      Codec used for data binding when (if) requested.
      protected java.io.Reader _reader
      Need to keep track of underlying Reader to be able to auto-close it (if required to)
      protected java.lang.String _textValue
      We need to keep track of text values.
      protected org.yaml.snakeyaml.parser.ParserImpl _yamlParser  
      protected org.yaml.snakeyaml.resolver.Resolver _yamlResolver  
      private static java.util.regex.Pattern PATTERN_FLOAT
      We will use pattern that is bit stricter than YAML definition, but we will still allow things like extra '_' in there.
      • 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, _numberInt, _numberLong, _numberNegative, _numTypesValid, _parsingContext, _textBuffer, _tokenInputCol, _tokenInputRow, _tokenInputTotal
      • 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
      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, java.io.Reader reader)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private com.fasterxml.jackson.core.JsonToken _cleanYamlFloat​(java.lang.String str)  
      private com.fasterxml.jackson.core.JsonToken _cleanYamlInt​(java.lang.String str)
      Helper method used to clean up YAML floating-point value so it can be parsed using standard JDK classes.
      protected void _closeInput()  
      protected com.fasterxml.jackson.core.JsonToken _decodeIntWithUnderscores​(java.lang.String value, int len)  
      protected com.fasterxml.jackson.core.JsonToken _decodeNumberScalar​(java.lang.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 java.lang.Boolean _matchYAMLBoolean​(java.lang.String value, int len)  
      protected int _parseIntValue()  
      protected void _parseNumericValue​(int expType)  
      boolean canReadObjectId()  
      boolean canReadTypeId()  
      com.fasterxml.jackson.core.JsonParser configure​(YAMLParser.Feature f, boolean state)
      Method for enabling or disabling specified CSV feature (check YAMLParser.Feature for list of features)
      com.fasterxml.jackson.core.JsonParser disable​(YAMLParser.Feature f)
      Method for disabling specified CSV feature (check YAMLParser.Feature for list of features)
      com.fasterxml.jackson.core.JsonParser enable​(YAMLParser.Feature f)
      Method for enabling specified CSV feature (check YAMLParser.Feature for list of features)
      com.fasterxml.jackson.core.ObjectCodec getCodec()  
      java.lang.String getCurrentAnchor()
      Deprecated.
      Since 2.3 (was added in 2.1) -- use getObjectId() instead
      com.fasterxml.jackson.core.JsonLocation getCurrentLocation()  
      java.lang.String getCurrentName()  
      java.lang.Object getEmbeddedObject()  
      int getFormatFeatures()  
      java.lang.String getObjectId()  
      java.lang.String getText()  
      int getText​(java.io.Writer writer)  
      char[] getTextCharacters()  
      int getTextLength()  
      int getTextOffset()  
      com.fasterxml.jackson.core.JsonLocation getTokenLocation()  
      java.lang.String getTypeId()  
      boolean hasTextCharacters()  
      boolean isCurrentAlias()
      Method that can be used to check whether current token was created from YAML Alias token (reference to an anchor).
      boolean isEnabled​(YAMLParser.Feature f)
      Method for checking whether specified CSV YAMLParser.Feature is enabled.
      com.fasterxml.jackson.core.JsonToken nextToken()  
      com.fasterxml.jackson.core.JsonParser overrideFormatFeatures​(int values, int mask)  
      int readBinaryValue​(com.fasterxml.jackson.core.Base64Variant b64variant, java.io.OutputStream out)  
      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, _decodeBase64Escape, _decodeBase64Escape, _decodeEscaped, _eofAsNextChar, _finishString, _getByteArrayBuilder, _getSourceReference, _handleBase64MissingPadding, _handleEOF, _handleUnrecognizedCharacterEscape, _releaseBuffers, _reportMismatchedEndMarker, _reportTooLongIntegral, _throwUnquotedSpace, _validJsonTokenList, _validJsonValueList, close, convertNumberToBigDecimal, convertNumberToBigInteger, convertNumberToDouble, convertNumberToInt, convertNumberToLong, disable, enable, getBigIntegerValue, getBinaryValue, getCurrentValue, getDecimalValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getNumberType, getNumberValue, getParsingContext, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, growArrayBy, isClosed, isNaN, loadMore, loadMoreGuaranteed, overrideCurrentName, overrideStdFeatures, reportInvalidBase64Char, reportInvalidBase64Char, reset, resetAsNaN, resetFloat, resetInt, setCurrentValue, setFeatureMask
      • 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, getValueAsString, getValueAsString, hasCurrentToken, hasToken, hasTokenId, isExpectedStartArrayToken, isExpectedStartObjectToken, nextValue, reportInvalidNumber, reportOverflowInt, reportOverflowInt, reportOverflowInt, reportOverflowLong, reportOverflowLong, reportOverflowLong, reportUnexpectedNumberChar, skipChildren
      • Methods inherited from class com.fasterxml.jackson.core.JsonParser

        _codec, _constructError, _reportUnsupportedOperation, canParseAsync, canUseSchema, configure, currentName, finishToken, getBinaryValue, getBooleanValue, getByteValue, getFeatureMask, getInputSource, getNonBlockingInputFeeder, getSchema, getShortValue, getValueAsBoolean, getValueAsDouble, isEnabled, isEnabled, nextBooleanValue, nextFieldName, nextFieldName, nextIntValue, nextLongValue, nextTextValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, requiresCustomCodec, setRequestPayloadOnError, setRequestPayloadOnError, setRequestPayloadOnError, setSchema
      • Methods inherited from class java.lang.Object

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

      • PATTERN_FLOAT

        private static final java.util.regex.Pattern PATTERN_FLOAT
        We will use pattern that is bit stricter than YAML definition, but we will still allow things like extra '_' in there.
      • _objectCodec

        protected com.fasterxml.jackson.core.ObjectCodec _objectCodec
        Codec used for data binding when (if) requested.
      • _formatFeatures

        protected int _formatFeatures
      • _reader

        protected final java.io.Reader _reader
        Need to keep track of underlying Reader 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 _lastEvent
        Keep track of the last event read, to get access to Location info
      • _textValue

        protected java.lang.String _textValue
        We need to keep track of text values.
      • _cleanedTextValue

        protected java.lang.String _cleanedTextValue
        For some tokens (specifically, numbers), we'll have cleaned up version, mostly free of underscores
      • _currentFieldName

        protected java.lang.String _currentFieldName
        Let's also have a local copy of the current field name
      • _currentIsAlias

        protected boolean _currentIsAlias
        Flag that is set when current token was derived from an Alias (reference to another value's anchor)
        Since:
        2.1
      • _currentAnchor

        protected java.lang.String _currentAnchor
        Anchor for the value that parser currently points to: in case of structured types, value whose first token current token is.
    • Constructor Detail

      • YAMLParser

        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,
                          java.io.Reader reader)
    • Method Detail

      • 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
      • 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
        public java.lang.String getCurrentAnchor()
        Deprecated.
        Since 2.3 (was added in 2.1) -- use getObjectId() instead
        Method 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 interface com.fasterxml.jackson.core.Versioned
        Overrides:
        version in class com.fasterxml.jackson.core.base.ParserBase
      • _closeInput

        protected void _closeInput()
                            throws java.io.IOException
        Specified by:
        _closeInput in class com.fasterxml.jackson.core.base.ParserBase
        Throws:
        java.io.IOException
      • 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
      • disable

        public com.fasterxml.jackson.core.JsonParser disable​(YAMLParser.Feature f)
        Method for disabling specified CSV feature (check YAMLParser.Feature for list of features)
      • configure

        public com.fasterxml.jackson.core.JsonParser configure​(YAMLParser.Feature f,
                                                               boolean state)
        Method for enabling or disabling specified CSV feature (check YAMLParser.Feature for list of features)
      • getTokenLocation

        public com.fasterxml.jackson.core.JsonLocation getTokenLocation()
        Overrides:
        getTokenLocation in class com.fasterxml.jackson.core.base.ParserBase
      • getCurrentLocation

        public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
        Overrides:
        getCurrentLocation in class com.fasterxml.jackson.core.base.ParserBase
      • _locationFor

        protected com.fasterxml.jackson.core.JsonLocation _locationFor​(org.yaml.snakeyaml.error.Mark m)
      • 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
      • _decodeScalar

        protected com.fasterxml.jackson.core.JsonToken _decodeScalar​(org.yaml.snakeyaml.events.ScalarEvent scalar)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • _matchYAMLBoolean

        protected java.lang.Boolean _matchYAMLBoolean​(java.lang.String value,
                                                      int len)
      • _decodeNumberScalar

        protected com.fasterxml.jackson.core.JsonToken _decodeNumberScalar​(java.lang.String value,
                                                                           int len)
      • _decodeIntWithUnderscores

        protected com.fasterxml.jackson.core.JsonToken _decodeIntWithUnderscores​(java.lang.String value,
                                                                                 int len)
      • hasTextCharacters

        public boolean hasTextCharacters()
        Overrides:
        hasTextCharacters in class com.fasterxml.jackson.core.base.ParserBase
      • 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
      • getCurrentName

        public java.lang.String getCurrentName()
                                        throws java.io.IOException
        Overrides:
        getCurrentName in class com.fasterxml.jackson.core.base.ParserBase
        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
      • 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
      • readBinaryValue

        public int readBinaryValue​(com.fasterxml.jackson.core.Base64Variant b64variant,
                                   java.io.OutputStream out)
                            throws java.io.IOException
        Overrides:
        readBinaryValue in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
      • _parseNumericValue

        protected void _parseNumericValue​(int expType)
                                   throws java.io.IOException
        Overrides:
        _parseNumericValue in class com.fasterxml.jackson.core.base.ParserBase
        Throws:
        java.io.IOException
      • _parseIntValue

        protected int _parseIntValue()
                              throws java.io.IOException
        Overrides:
        _parseIntValue in class com.fasterxml.jackson.core.base.ParserBase
        Throws:
        java.io.IOException
      • canReadObjectId

        public boolean canReadObjectId()
        Overrides:
        canReadObjectId in class com.fasterxml.jackson.core.JsonParser
      • canReadTypeId

        public boolean canReadTypeId()
        Overrides:
        canReadTypeId in class com.fasterxml.jackson.core.JsonParser
      • getObjectId

        public java.lang.String getObjectId()
                                     throws java.io.IOException,
                                            com.fasterxml.jackson.core.JsonGenerationException
        Overrides:
        getObjectId in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
        com.fasterxml.jackson.core.JsonGenerationException
      • getTypeId

        public java.lang.String getTypeId()
                                   throws java.io.IOException,
                                          com.fasterxml.jackson.core.JsonGenerationException
        Overrides:
        getTypeId in class com.fasterxml.jackson.core.JsonParser
        Throws:
        java.io.IOException
        com.fasterxml.jackson.core.JsonGenerationException
      • _cleanYamlInt

        private com.fasterxml.jackson.core.JsonToken _cleanYamlInt​(java.lang.String str)
        Helper method used to clean up YAML floating-point value so it can be parsed using standard JDK classes. Currently this just means stripping out optional underscores.
      • _cleanYamlFloat

        private com.fasterxml.jackson.core.JsonToken _cleanYamlFloat​(java.lang.String str)