Class YAMLAnchorReplayingParser

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

    public class YAMLAnchorReplayingParser
    extends YAMLParser
    A parser that remembers the events of anchored parts in yaml and repeats them to inline these parts when an alias if found instead of only returning an alias.

    Note: this overwrites the getEvent() since the base `super.nextToken()` manages to much state and it seems to be much simpler to re-emit the events.

    Since:
    2.19
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  YAMLAnchorReplayingParser.AnchorContext  
      • 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

      Fields 
      Modifier and Type Field Description
      private int globalDepth
      keeps track of the global depth of nested collections
      static int MAX_ANCHORS
      the maximum limit of anchors to remember
      static int MAX_EVENTS
      the maximum number of events that can be replayed
      static int MAX_MERGES
      the maximum limit of merges to follow
      static int MAX_REFS
      the maximum limit of references to remember
      private java.util.ArrayDeque<java.lang.Integer> mergeStack
      Remembers when a merge has been started in order to skip the corresponding sequence end which needs to be excluded
      private java.util.Map<java.lang.String,​java.util.List<org.yaml.snakeyaml.events.Event>> referencedObjects
      Keeps track of the last sequentially found definition of each anchor
      private java.util.ArrayDeque<org.yaml.snakeyaml.events.Event> refEvents
      Keeps track of events that have been insert when processing alias
      private java.util.ArrayDeque<YAMLAnchorReplayingParser.AnchorContext> tokenStack
      Collects nested anchor definitions
      • 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_RS, 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

      Constructors 
      Constructor Description
      YAMLAnchorReplayingParser​(com.fasterxml.jackson.core.io.IOContext ctxt, int parserFeatures, int formatFeatures, org.yaml.snakeyaml.LoaderOptions loaderOptions, com.fasterxml.jackson.core.ObjectCodec codec, java.io.Reader reader)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.yaml.snakeyaml.events.Event filterEvent​(org.yaml.snakeyaml.events.Event event)  
      private void finishContext​(YAMLAnchorReplayingParser.AnchorContext context)  
      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.
      protected org.yaml.snakeyaml.events.Event trackDepth​(org.yaml.snakeyaml.events.Event event)  
      • 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, _reportExtraEndMarker, _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
      • Methods inherited from class java.lang.Object

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

      • MAX_EVENTS

        public static final int MAX_EVENTS
        the maximum number of events that can be replayed
        See Also:
        Constant Field Values
      • MAX_ANCHORS

        public static final int MAX_ANCHORS
        the maximum limit of anchors to remember
        See Also:
        Constant Field Values
      • MAX_MERGES

        public static final int MAX_MERGES
        the maximum limit of merges to follow
        See Also:
        Constant Field Values
      • MAX_REFS

        public static final int MAX_REFS
        the maximum limit of references to remember
        See Also:
        Constant Field Values
      • mergeStack

        private final java.util.ArrayDeque<java.lang.Integer> mergeStack
        Remembers when a merge has been started in order to skip the corresponding sequence end which needs to be excluded
      • referencedObjects

        private final java.util.Map<java.lang.String,​java.util.List<org.yaml.snakeyaml.events.Event>> referencedObjects
        Keeps track of the last sequentially found definition of each anchor
      • refEvents

        private final java.util.ArrayDeque<org.yaml.snakeyaml.events.Event> refEvents
        Keeps track of events that have been insert when processing alias
      • globalDepth

        private int globalDepth
        keeps track of the global depth of nested collections
    • Constructor Detail

      • YAMLAnchorReplayingParser

        public YAMLAnchorReplayingParser​(com.fasterxml.jackson.core.io.IOContext ctxt,
                                         int parserFeatures,
                                         int formatFeatures,
                                         org.yaml.snakeyaml.LoaderOptions loaderOptions,
                                         com.fasterxml.jackson.core.ObjectCodec codec,
                                         java.io.Reader reader)
    • Method Detail

      • finishContext

        private void finishContext​(YAMLAnchorReplayingParser.AnchorContext context)
                            throws com.fasterxml.jackson.core.exc.StreamConstraintsException
        Throws:
        com.fasterxml.jackson.core.exc.StreamConstraintsException
      • trackDepth

        protected org.yaml.snakeyaml.events.Event trackDepth​(org.yaml.snakeyaml.events.Event event)
      • filterEvent

        protected org.yaml.snakeyaml.events.Event filterEvent​(org.yaml.snakeyaml.events.Event event)
      • getEvent

        protected org.yaml.snakeyaml.events.Event getEvent()
                                                    throws java.io.IOException
        Description copied from class: YAMLParser
        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.

        NOTE: since 2.18, declared to throw IOException to allow sub-classes to do so.

        Overrides:
        getEvent in class YAMLParser
        Throws:
        java.io.IOException