Package io.micronaut.serde.support
Class AbstractStreamDecoder
java.lang.Object
io.micronaut.serde.LimitingStream
io.micronaut.serde.support.AbstractStreamDecoder
- All Implemented Interfaces:
io.micronaut.serde.Decoder,AutoCloseable
- Direct Known Subclasses:
AbstractDecoderPerStructureStreamDecoder
@Internal
public abstract class AbstractStreamDecoder
extends io.micronaut.serde.LimitingStream
implements io.micronaut.serde.Decoder
Abstract base class for stream-based
Decoders.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumThe token type.static interfaceDecoder function for a single value.Nested classes/interfaces inherited from class io.micronaut.serde.LimitingStream
io.micronaut.serde.LimitingStream.RemainingLimits -
Field Summary
Fields inherited from class io.micronaut.serde.LimitingStream
DEFAULT_LIMITS, DEFAULT_MAXIMUM_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionAbstractStreamDecoder(@NonNull io.micronaut.serde.LimitingStream.RemainingLimits remainingLimits) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringcoerceScalarToString(AbstractStreamDecoder.TokenType currentToken) Decode any non-null scalar value (number, string or boolean) to its string representation.protected voidconsumeLeftElements(AbstractStreamDecoder.TokenType currentToken) Consumes left elements.protected abstract @Nullable AbstractStreamDecoder.TokenTypefinal @Nullable Objectfinal @NonNull io.micronaut.serde.DecoderdecodeArray(io.micronaut.core.type.Argument<?> type) protected AbstractStreamDecoderdecodeArray0(AbstractStreamDecoder.TokenType currentToken) Decodes the array.final @NonNull BigDecimalfinal @NonNull BigIntegerbyte @NonNull []final booleanio.micronaut.serde.Decoderfinal bytefinal charprotected final <T> TdecodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction) Decode a custom type.protected final <T> TdecodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction, boolean callNext) Decode a custom type.final doublefinal floatfinal int@Nullable Stringfinal long@NonNull io.micronaut.json.tree.JsonNodefinal booleanprotected final <T> TdecodeNumber(AbstractStreamDecoder.TokenType currentToken, AbstractStreamDecoder.ValueDecoder<T> fromNumberToken, Function<String, T> fromString, T zero, T one) Decode a number type, applying all necessary coercions.final @NonNull io.micronaut.serde.DecoderdecodeObject(io.micronaut.core.type.Argument<?> type) protected AbstractStreamDecoderdecodeObject0(AbstractStreamDecoder.TokenType currentToken) Decodes the object.final short@NonNull StringvoidfinishStructure(boolean consumeLeftElements) protected abstract NumberDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue.protected io.micronaut.json.tree.JsonNodeDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a numericJsonNode.protected abstract BigDecimalDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue.protected abstract BigIntegerDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue.protected abstract booleanDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue.protected abstract StringGet the current object field name.protected abstract doubleDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value.protected intDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value.protected abstract longgetLong()Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value.protected abstract StringDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue.booleanprotected abstract voidMove to the next token.protected voidpreDecodeValue(AbstractStreamDecoder.TokenType currentToken) Should be called before attempting to decode a value.protected abstract voidIf we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY.final voidprotected IOExceptionMethods inherited from class io.micronaut.serde.LimitingStream
childLimits, decreaseDepth, increaseDepth, limitsFromConfiguration, ourLimitsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.serde.Decoder
close, createDeserializationException, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure
-
Constructor Details
-
AbstractStreamDecoder
public AbstractStreamDecoder(@NonNull @NonNull io.micronaut.serde.LimitingStream.RemainingLimits remainingLimits)
-
-
Method Details
-
currentToken
- Returns:
- The current token.
-
nextToken
Move to the next token.- Throws:
IOException- if an unrecoverable error occurs
-
unexpectedToken
- Parameters:
expected- The token type that was expected in place ofcurrentToken().- Returns:
- The exception that should be thrown to signify an unexpected token.
-
preDecodeValue
Should be called before attempting to decode a value. Has basic sanity checks, such as confirming we're not currently in aAbstractStreamDecoder.TokenType.KEYand that there's no child decoder currently running.- Parameters:
currentToken- The current token
-
finishStructure
- Specified by:
finishStructurein interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
consumeLeftElements
Consumes left elements.- Parameters:
currentToken- The current token- Throws:
IOException
-
hasNextArrayValue
public boolean hasNextArrayValue()- Specified by:
hasNextArrayValuein interfaceio.micronaut.serde.Decoder
-
getCurrentKey
Get the current object field name. Only called forAbstractStreamDecoder.TokenType.KEY.- Returns:
- The current field key
- Throws:
IOException- if an unrecoverable error occurs
-
decodeKey
- Specified by:
decodeKeyin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeArray
@NonNull public final @NonNull io.micronaut.serde.Decoder decodeArray(io.micronaut.core.type.Argument<?> type) throws IOException - Specified by:
decodeArrayin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeArray0
protected AbstractStreamDecoder decodeArray0(AbstractStreamDecoder.TokenType currentToken) throws IOException Decodes the array.- Parameters:
currentToken- The current token- Returns:
- The decoder
- Throws:
IOException- The exception
-
decodeObject
@NonNull public final @NonNull io.micronaut.serde.Decoder decodeObject(io.micronaut.core.type.Argument<?> type) throws IOException - Specified by:
decodeObjectin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeObject0
protected AbstractStreamDecoder decodeObject0(AbstractStreamDecoder.TokenType currentToken) throws IOException Decodes the object.- Parameters:
currentToken- The current token- Returns:
- The decoder
- Throws:
IOException- The exception
-
coerceScalarToString
protected abstract String coerceScalarToString(AbstractStreamDecoder.TokenType currentToken) throws IOException Decode any non-null scalar value (number, string or boolean) to its string representation.- Parameters:
currentToken- The current token- Returns:
- The current value, coerced to a string
- Throws:
IOException- if an unrecoverable error occurs
-
decodeString
- Specified by:
decodeStringin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
getString
Decode the currentAbstractStreamDecoder.TokenType.STRINGvalue. Called for no other token type.- Returns:
- The String value
- Throws:
IOException- if an unrecoverable error occurs
-
getBoolean
Decode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue. Called for no other token type.- Returns:
- The boolean value
- Throws:
IOException- if an unrecoverable error occurs
-
decodeBoolean
- Specified by:
decodeBooleanin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeByte
- Specified by:
decodeBytein interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeShort
- Specified by:
decodeShortin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeChar
- Specified by:
decodeCharin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeInt
- Specified by:
decodeIntin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeLong
- Specified by:
decodeLongin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
getLong
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getInteger
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getDouble
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBigInteger
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBigDecimal
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBestNumber
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue. Called for no other token type.- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBestNumberNode
Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a numericJsonNode. Called for no other token type. Default implementation tries to construct a node fromgetBestNumber().- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
decodeFloat
- Specified by:
decodeFloatin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeDouble
- Specified by:
decodeDoublein interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeBigInteger
- Specified by:
decodeBigIntegerin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeBigDecimal
- Specified by:
decodeBigDecimalin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeNumber
protected final <T> T decodeNumber(AbstractStreamDecoder.TokenType currentToken, AbstractStreamDecoder.ValueDecoder<T> fromNumberToken, Function<String, T> fromString, T zero, T one) throws IOExceptionDecode a number type, applying all necessary coercions.- Type Parameters:
T- The number type.- Parameters:
currentToken- The current tokenfromNumberToken- Called ifcurrentToken()is aAbstractStreamDecoder.TokenType.NUMBER.fromString- Called for the textual value ifcurrentToken()is aAbstractStreamDecoder.TokenType.STRING. Should throwNumberFormatExceptionon parse failure.zero- The zero value.one- The one value.- Returns:
- The parsed number.
- Throws:
IOException- if an unrecoverable error occurs
-
decodeBinary
- Specified by:
decodeBinaryin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeCustom
protected final <T> T decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction) throws IOException Decode a custom type.- Type Parameters:
T- Value type- Parameters:
readFunction- Function to call for reading the value. TheAbstractStreamDecoderparameter to the function will just bethis, but this allows subclasses to avoid capturingthisto avoid an allocation.- Returns:
- The parsed value.
- Throws:
IOException- if an unrecoverable error occurs
-
decodeCustom
protected final <T> T decodeCustom(AbstractStreamDecoder.ValueDecoder<T> readFunction, boolean callNext) throws IOException Decode a custom type.- Type Parameters:
T- Value type- Parameters:
readFunction- Function to call for reading the value. TheAbstractStreamDecoderparameter to the function will just bethis, but this allows subclasses to avoid capturingthisto avoid an allocation.callNext- Pass "true" if next token should be read after invocation- Returns:
- The parsed value.
- Throws:
IOException- if an unrecoverable error occurs
-
decodeNull
- Specified by:
decodeNullin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeBuffer
- Specified by:
decodeBufferin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeNode
- Specified by:
decodeNodein interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
decodeArbitrary
- Specified by:
decodeArbitraryin interfaceio.micronaut.serde.Decoder- Throws:
IOException
-
skipChildren
If we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY. Else, do nothing.- Throws:
IOException- if an unrecoverable error occurs
-
skipValue
- Specified by:
skipValuein interfaceio.micronaut.serde.Decoder- Throws:
IOException
-