Class YAMLAnchorReplayingParser

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
com.fasterxml.jackson.dataformat.yaml.YAMLAnchorReplayingParser
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, Closeable, 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 
     

    Nested classes/interfaces inherited from class com.fasterxml.jackson.dataformat.yaml.YAMLParser

    YAMLParser.Feature

    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
    keeps track of the global depth of nested collections
    static final int
    the maximum limit of anchors to remember
    static final int
    the maximum number of events that can be replayed
    static final int
    the maximum limit of merges to follow
    static final int
    the maximum limit of references to remember
    private final ArrayDeque<Integer>
    Remembers when a merge has been started in order to skip the corresponding sequence end which needs to be excluded
    private final Map<String,List<org.yaml.snakeyaml.events.Event>>
    Keeps track of the last sequentially found definition of each anchor
    private final ArrayDeque<org.yaml.snakeyaml.events.Event>
    Keeps track of events that have been insert when processing alias
    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, Reader reader)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.yaml.snakeyaml.events.Event
    filterEvent(org.yaml.snakeyaml.events.Event event)
     
    private void
     
    protected org.yaml.snakeyaml.events.Event
    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 Details

    • MAX_EVENTS

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

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

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

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

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

      Collects nested anchor definitions
    • referencedObjects

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

      private final 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 Details

    • 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, Reader reader)
  • Method Details

    • 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 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:
      IOException