Package io.micronaut.serde.bson
Class BsonReaderDecoder
java.lang.Object
io.micronaut.serde.LimitingStream
io.micronaut.serde.support.AbstractStreamDecoder
io.micronaut.serde.support.AbstractDecoderPerStructureStreamDecoder
io.micronaut.serde.bson.BsonReaderDecoder
- All Implemented Interfaces:
Decoder,AutoCloseable
Bson implementation of
Decoder.- Author:
- Denis Stepanov
-
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
ConstructorsConstructorDescriptionBsonReaderDecoder(org.bson.BsonReader bsonReader, @NonNull LimitingStream.RemainingLimits remainingLimits) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled when the old child has finished processing and returns control of the stream to the parent.protected StringcoerceScalarToString(AbstractStreamDecoder.TokenType currentToken) Decode any non-null scalar value (number, string or boolean) to its string representation.protected AbstractStreamDecoderCreate a new child decoder usingAbstractDecoderPerStructureStreamDecoder(AbstractDecoderPerStructureStreamDecoder,io.micronaut.serde.LimitingStream.RemainingLimits).createDeserializationException(String message, Object invalidValue) Creates an exception for the given message.protected AbstractStreamDecoder.TokenTypebyte @NonNull []Decode binary data from this stream.Buffer the whole subtree of this value and return it as a newDecoder.<T> TdecodeCustom(org.bson.codecs.Decoder<T> decoder, org.bson.codecs.DecoderContext context) org.bson.types.Decimal128DecodesDecimal128.org.bson.types.ObjectIdDecodesObjectId.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 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 io.micronaut.serde.support.AbstractDecoderPerStructureStreamDecoder
decodeArray0, decodeKey, decodeObject0, finishStructure, hasNextArrayValue, preDecodeValueMethods inherited from class io.micronaut.serde.support.AbstractStreamDecoder
consumeLeftElements, decodeArbitrary, decodeArray, decodeBigDecimal, decodeBigInteger, decodeBoolean, decodeByte, decodeChar, decodeCustom, decodeCustom, decodeDouble, decodeFloat, decodeInt, decodeLong, decodeNode, decodeNull, decodeNumber, decodeObject, decodeShort, decodeString, getBestNumberNode, getInteger, skipValue, unexpectedTokenMethods 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, decodeArray, decodeBigDecimalNullable, decodeBigIntegerNullable, decodeBinaryNullable, decodeBooleanNullable, decodeByteNullable, decodeCharNullable, decodeDoubleNullable, decodeFloatNullable, decodeIntNullable, decodeLongNullable, decodeNumber, decodeNumberNullable, decodeObject, decodeShortNullable, decodeStringNullable, finishStructure
-
Constructor Details
-
BsonReaderDecoder
public BsonReaderDecoder(org.bson.BsonReader bsonReader, @NonNull @NonNull LimitingStream.RemainingLimits remainingLimits)
-
-
Method Details
-
backFromChild
Description copied from class:AbstractDecoderPerStructureStreamDecoderCalled when the old child has finished processing and returns control of the stream to the parent. Current token is assumed to beAbstractStreamDecoder.TokenType.END_ARRAYorAbstractStreamDecoder.TokenType.END_OBJECT. However weAbstractStreamDecoder.currentToken()may hold an outdated value untilAbstractStreamDecoder.nextToken()is called, which this method does.- Overrides:
backFromChildin classAbstractDecoderPerStructureStreamDecoder- Parameters:
child- The now-invalid child decoder.- Throws:
IOException- if an unrecoverable error occurs
-
nextToken
protected void nextToken()Description copied from class:AbstractStreamDecoderMove to the next token.- Specified by:
nextTokenin classAbstractStreamDecoder
-
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
-
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
-
createChildDecoder
Description copied from class:AbstractDecoderPerStructureStreamDecoderCreate a new child decoder usingAbstractDecoderPerStructureStreamDecoder(AbstractDecoderPerStructureStreamDecoder,io.micronaut.serde.LimitingStream.RemainingLimits).- Specified by:
createChildDecoderin classAbstractDecoderPerStructureStreamDecoder- Returns:
- The new decoder
- Throws:
SerdeException
-
getString
Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.STRINGvalue. Called for no other token type.- Specified by:
getStringin classAbstractStreamDecoder- Returns:
- The String value
-
getBoolean
protected boolean getBoolean()Description copied from class:AbstractStreamDecoderDecode the currentAbstractStreamDecoder.TokenType.BOOLEANvalue. Called for no other token type.- Specified by:
getBooleanin classAbstractStreamDecoder- Returns:
- The boolean value
-
getLong
protected long 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
-
getDouble
protected double 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
-
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
-
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
-
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
-
decodeBinary
Description copied from interface:DecoderDecode binary data from this stream. Binary data can be serialized in multiple different ways that differ by format.- An array of numbers must be supported by all implementations, for compatibility. This is also the default implementation.
- A base64 string. This is convenient for text-based formats like json, and is supported by jackson.
- A format-specific type, for binary formats such as bson.
- Other format specific behavior. Oracle JDBC Json will parse strings as hex, for example.
- Specified by:
decodeBinaryin interfaceDecoder- Overrides:
decodeBinaryin classAbstractStreamDecoder- Returns:
- The decoded byte array
- Throws:
IOException
-
skipChildren
protected void 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
-
currentToken
- Specified by:
currentTokenin classAbstractStreamDecoder- Returns:
- The current token.
-
createDeserializationException
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
-
decodeDecimal128
DecodesDecimal128.- Returns:
- decoded value
- Throws:
IOException
-
decodeObjectId
DecodesObjectId.- Returns:
- decoded value
- Throws:
IOException
-
decodeCustom
public <T> T decodeCustom(org.bson.codecs.Decoder<T> decoder, org.bson.codecs.DecoderContext context) throws IOException - Throws:
IOException
-
decodeBuffer
Description copied from interface:DecoderBuffer the whole subtree of this value and return it as a newDecoder. The returnedDecodercan be used independently to thisDecoder. This means actual parsing of the subtree can be delayed.The returned
Decodershould behave identically to thisDecoder. This means that for exampledecoder.decodeDouble()should be equivalent todecoder.decodeBuffer().decodeDouble().- Specified by:
decodeBufferin interfaceDecoder- Overrides:
decodeBufferin classAbstractStreamDecoder- Returns:
- An independent decoder that visits this subtree.
- Throws:
IOException- If an unrecoverable error occurs
-