Class YamlDecoder
java.lang.Object
io.micronaut.serde.LimitingStream
io.micronaut.serde.support.AbstractStreamDecoder
io.micronaut.serde.yaml.YamlDecoder
- All Implemented Interfaces:
Decoder, AutoCloseable
YAML implementation of the
Decoder interface.
The decoder reads exactly one YAML document. The root node may be a mapping, a sequence or a scalar. Anchors, aliases and merge keys are resolved while reading, quoted scalars are always strings, and plain scalars are typed with the YAML 1.2 core schema. Additional documents in the input are rejected.
- Since:
- 3.2.0
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractStreamDecoder
AbstractStreamDecoder.TokenType, AbstractStreamDecoder.ValueDecoder<R>Nested classes/interfaces inherited from class LimitingStream
LimitingStream.RemainingLimits -
Field Summary
Fields inherited from class LimitingStream
DEFAULT_LIMITS, DEFAULT_MAXIMUM_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionYamlDecoder(@NonNull InputStream inputStream, @NonNull LimitingStream.RemainingLimits remainingLimits) Creates a YAML decoder with the default read settings and every coercion allowed. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcoerceScalarToString(AbstractStreamDecoder.TokenType currentToken) Decode any non-null scalar value (number, string or boolean) to its string representation.@NonNull IOExceptioncreateDeserializationException(@NonNull String message, @Nullable Object invalidValue) Creates an exception for the given message.protected @Nullable AbstractStreamDecoder.TokenTypevoidfinishStructure(boolean consumeLeftElements) protected NumberDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue.protected BigDecimalDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue.protected BigIntegerDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue.protected booleanDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue.protected StringGet the current object field name.protected doubleDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value.protected longgetLong()Decode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value.protected StringDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue.protected booleanWhether the currentAbstractStreamDecoder.TokenType.NUMBERtoken has a fractional part.protected voidMove to the next token.protected voidIf we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY.Methods inherited from class AbstractStreamDecoder
consumeLeftElements, decodeArbitrary, decodeArray, decodeArray0, decodeBigDecimal, decodeBigInteger, decodeBinary, decodeBoolean, decodeBuffer, decodeByte, decodeChar, decodeCustom, decodeCustom, decodeDouble, decodeFloat, decodeInt, decodeKey, decodeLong, decodeNode, decodeNull, decodeNumber, decodeObject, decodeObject0, decodeShort, decodeString, getBestNumberNode, getBigDecimalFromNumber, getCoercionPolicy, getInteger, hasNextArrayValue, preDecodeValue, skipValue, unexpectedTokenMethods inherited from class LimitingStream
childLimits, decreaseDepth, increaseDepth, limitsFromConfiguration, ourLimitsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Decoder
close, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeNumber, decodeNumberNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure
-
Constructor Details
-
YamlDecoder
public YamlDecoder(@NonNull InputStream inputStream, @NonNull LimitingStream.RemainingLimits remainingLimits) throws IOException Creates a YAML decoder with the default read settings and every coercion allowed.- Parameters:
inputStream- The YAML input streamremainingLimits- The remaining stream limits- Throws:
IOException- if the input cannot be read or holds no YAML document
-
-
Method Details
-
currentToken
- Specified by:
currentTokenin classAbstractStreamDecoder- Returns:
- The current token.
-
nextToken
Description copied from class:AbstractStreamDecoderMove to the next token.- Specified by:
nextTokenin classAbstractStreamDecoder- Throws:
IOException- if an unrecoverable error occurs
-
getCurrentKey
Description copied from class:AbstractStreamDecoderGet the current object field name. Only called forAbstractStreamDecoder.TokenType.KEY.- Specified by:
getCurrentKeyin classAbstractStreamDecoder- Returns:
- The current field key
- Throws:
IOException- if an unrecoverable error occurs
-
coerceScalarToString
protected String coerceScalarToString(AbstractStreamDecoder.TokenType currentToken) throws IOException Description copied from class:AbstractStreamDecoderDecode any non-null scalar value (number, string or boolean) to its string representation.- Specified by:
coerceScalarToStringin classAbstractStreamDecoder- Parameters:
currentToken- The current token- Returns:
- The current value, coerced to a string
- Throws:
IOException- if an unrecoverable error occurs
-
getString
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue. Called for no other token type.- Specified by:
getStringin classAbstractStreamDecoder- Returns:
- The String value
- Throws:
IOException- if an unrecoverable error occurs
-
getBoolean
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue. Called for no other token type.- Specified by:
getBooleanin classAbstractStreamDecoder- Returns:
- The boolean value
- Throws:
IOException- if an unrecoverable error occurs
-
isCurrentNumberFloat
protected boolean isCurrentNumberFloat()Description copied from class:AbstractStreamDecoderWhether the currentAbstractStreamDecoder.TokenType.NUMBERtoken has a fractional part. Only called when the configuration forbids reading a floating point number as an integer, so a decoder that never sees that configuration keeps working without implementing it.The default implementation materialises the number with
AbstractStreamDecoder.getBestNumber(). A decoder whose underlying parser consumes the value when it is read, as a forward only BSON reader does, must override this and answer from the token type instead.- Overrides:
isCurrentNumberFloatin classAbstractStreamDecoder- Returns:
trueif the current number is a floating point number
-
getLong
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a long value. Called for no other token type.- Specified by:
getLongin classAbstractStreamDecoder- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getDouble
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as a double value. Called for no other token type.- Specified by:
getDoublein classAbstractStreamDecoder- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBigInteger
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigIntegervalue. Called for no other token type.- Specified by:
getBigIntegerin classAbstractStreamDecoder- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBigDecimal
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aBigDecimalvalue. Called for no other token type.- Specified by:
getBigDecimalin classAbstractStreamDecoder- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
getBestNumber
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.NUMBERvalue as aNumbervalue. Called for no other token type.- Specified by:
getBestNumberin classAbstractStreamDecoder- Returns:
- The number value
- Throws:
IOException- if an unrecoverable error occurs
-
skipChildren
Description copied from class:AbstractStreamDecoderIf we are at aAbstractStreamDecoder.TokenType.START_OBJECTorAbstractStreamDecoder.TokenType.START_ARRAY, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECTorAbstractStreamDecoder.TokenType.END_ARRAY. Else, do nothing.- Specified by:
skipChildrenin classAbstractStreamDecoder- Throws:
IOException- if an unrecoverable error occurs
-
finishStructure
- Specified by:
finishStructurein interfaceDecoder- Overrides:
finishStructurein classAbstractStreamDecoder- Parameters:
consumeLeftElements- True to consume left elements- Throws:
IOException- If an unrecoverable error occurs
-
createDeserializationException
public @NonNull IOException createDeserializationException(@NonNull String message, @Nullable Object invalidValue) Description copied from interface:DecoderCreates an exception for the given message.- Parameters:
message- The message, nevernullinvalidValue- The invalid value. Can benull.- Returns:
- The exception, never
null
-