Package io.micronaut.serde.support
Class AbstractDecoderPerStructureStreamDecoder
java.lang.Object
io.micronaut.serde.LimitingStream
io.micronaut.serde.support.AbstractStreamDecoder
io.micronaut.serde.support.AbstractDecoderPerStructureStreamDecoder
- All Implemented Interfaces:
Decoder
,AutoCloseable
- Direct Known Subclasses:
BsonReaderDecoder
@Internal
public abstract class AbstractDecoderPerStructureStreamDecoder
extends AbstractStreamDecoder
Abstract variation of
AbstractStreamDecoder
that uses separate decoders for structures like an array or an object.-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.serde.support.AbstractStreamDecoder
AbstractStreamDecoder.TokenType, AbstractStreamDecoder.ValueDecoder<R>
Nested classes/interfaces inherited from class io.micronaut.serde.LimitingStream
LimitingStream.RemainingLimits
-
Field Summary
Fields inherited from class io.micronaut.serde.LimitingStream
DEFAULT_LIMITS, DEFAULT_MAXIMUM_DEPTH
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractDecoderPerStructureStreamDecoder
(@NonNull LimitingStream.RemainingLimits remainingLimits) Root constructor.protected
AbstractDecoderPerStructureStreamDecoder
(@NonNull AbstractDecoderPerStructureStreamDecoder parent, @NonNull LimitingStream.RemainingLimits remainingLimits) Child constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called when the old child has finished processing and returns control of the stream to the parent.protected abstract AbstractStreamDecoder
Create a new child decoder usingAbstractDecoderPerStructureStreamDecoder(AbstractDecoderPerStructureStreamDecoder,io.micronaut.serde.LimitingStream.RemainingLimits)
.protected AbstractStreamDecoder
decodeArray0
(AbstractStreamDecoder.TokenType currentToken) Decodes the array.final String
Decodes a key, if there are no more keys to decode returnsnull
.protected AbstractStreamDecoder
decodeObject0
(AbstractStreamDecoder.TokenType currentToken) Decodes the object.void
finishStructure
(boolean consumeLeftElements) boolean
protected void
preDecodeValue
(AbstractStreamDecoder.TokenType currentToken) Should be called before attempting to decode a value.Methods inherited from class io.micronaut.serde.support.AbstractStreamDecoder
coerceScalarToString, consumeLeftElements, currentToken, decodeArbitrary, decodeArray, decodeBigDecimal, decodeBigInteger, decodeBinary, decodeBoolean, decodeBuffer, decodeByte, decodeChar, decodeCustom, decodeCustom, decodeDouble, decodeFloat, decodeInt, decodeLong, decodeNode, decodeNull, decodeNumber, decodeObject, decodeShort, decodeString, getBestNumber, getBestNumberNode, getBigDecimal, getBigInteger, getBoolean, getCurrentKey, getDouble, getInteger, getLong, getString, nextToken, skipChildren, skipValue, unexpectedToken
Methods inherited from class io.micronaut.serde.LimitingStream
childLimits, decreaseDepth, increaseDepth, limitsFromConfiguration, ourLimits
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.serde.Decoder
close, createDeserializationException, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeNumber, decodeNumberNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure
-
Constructor Details
-
AbstractDecoderPerStructureStreamDecoder
protected AbstractDecoderPerStructureStreamDecoder(@NonNull @NonNull AbstractDecoderPerStructureStreamDecoder parent, @NonNull @NonNull LimitingStream.RemainingLimits remainingLimits) Child constructor. Should inherit the parser from the parent.- Parameters:
parent
- The parent decoder.remainingLimits
- The limits for this decoder
-
AbstractDecoderPerStructureStreamDecoder
protected AbstractDecoderPerStructureStreamDecoder(@NonNull @NonNull LimitingStream.RemainingLimits remainingLimits) Root constructor.- Parameters:
remainingLimits
- The limits for this decoder
-
-
Method Details
-
createChildDecoder
Create a new child decoder usingAbstractDecoderPerStructureStreamDecoder(AbstractDecoderPerStructureStreamDecoder,io.micronaut.serde.LimitingStream.RemainingLimits)
.- Returns:
- The new decoder
- Throws:
SerdeException
-
preDecodeValue
Description copied from class:AbstractStreamDecoder
Should be called before attempting to decode a value. Has basic sanity checks, such as confirming we're not currently in aAbstractStreamDecoder.TokenType.KEY
and that there's no child decoder currently running.- Overrides:
preDecodeValue
in classAbstractStreamDecoder
- Parameters:
currentToken
- The current token
-
finishStructure
- Specified by:
finishStructure
in interfaceDecoder
- Overrides:
finishStructure
in classAbstractStreamDecoder
- Parameters:
consumeLeftElements
- True to consume left elements- Throws:
IOException
- If an unrecoverable error occurs
-
hasNextArrayValue
public boolean hasNextArrayValue()- Specified by:
hasNextArrayValue
in interfaceDecoder
- Overrides:
hasNextArrayValue
in classAbstractStreamDecoder
- Returns:
- Returns
true
if another array value is available.
-
decodeKey
Description copied from interface:Decoder
Decodes a key, if there are no more keys to decode returnsnull
.- Specified by:
decodeKey
in interfaceDecoder
- Overrides:
decodeKey
in classAbstractStreamDecoder
- Returns:
- The key or
null
if there aren't any more keys - Throws:
IOException
- If an unrecoverable error occurs
-
decodeArray0
protected AbstractStreamDecoder decodeArray0(AbstractStreamDecoder.TokenType currentToken) throws IOException Description copied from class:AbstractStreamDecoder
Decodes the array.- Overrides:
decodeArray0
in classAbstractStreamDecoder
- Parameters:
currentToken
- The current token- Returns:
- The decoder
- Throws:
IOException
- The exception
-
decodeObject0
protected AbstractStreamDecoder decodeObject0(AbstractStreamDecoder.TokenType currentToken) throws IOException Description copied from class:AbstractStreamDecoder
Decodes the object.- Overrides:
decodeObject0
in classAbstractStreamDecoder
- Parameters:
currentToken
- The current token- Returns:
- The decoder
- Throws:
IOException
- The exception
-
backFromChild
Called when the old child has finished processing and returns control of the stream to the parent. Current token is assumed to beAbstractStreamDecoder.TokenType.END_ARRAY
orAbstractStreamDecoder.TokenType.END_OBJECT
. However weAbstractStreamDecoder.currentToken()
may hold an outdated value untilAbstractStreamDecoder.nextToken()
is called, which this method does.- Parameters:
child
- The now-invalid child decoder.- Throws:
IOException
- if an unrecoverable error occurs
-