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
ConstructorDescriptionBsonReaderDecoder
(org.bson.BsonReader bsonReader, @NonNull LimitingStream.RemainingLimits remainingLimits) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called when the old child has finished processing and returns control of the stream to the parent.protected String
coerceScalarToString
(AbstractStreamDecoder.TokenType currentToken) Decode any non-null scalar value (number, string or boolean) to its string representation.protected AbstractStreamDecoder
Create 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.TokenType
byte @NonNull []
Decode binary data from this stream.Buffer the whole subtree of this value and return it as a newDecoder
.<T> T
decodeCustom
(org.bson.codecs.Decoder<T> decoder, org.bson.codecs.DecoderContext context) org.bson.types.Decimal128
DecodesDecimal128
.org.bson.types.ObjectId
DecodesObjectId
.protected Number
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aNumber
value.protected BigDecimal
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aBigDecimal
value.protected BigDecimal
getBigDecimalFromNumber
(Number number) Converts the number, probably retrieved by callingAbstractStreamDecoder.getBestNumber()
, to aBigDecimal
.protected BigInteger
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aBigInteger
value.protected boolean
Decode the currentAbstractStreamDecoder.TokenType.BOOLEAN
value.protected String
Get the current object field name.protected double
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as a double value.protected long
getLong()
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as a long value.protected String
Decode the currentAbstractStreamDecoder.TokenType.STRING
value.protected void
Move to the next token.protected void
If we are at aAbstractStreamDecoder.TokenType.START_OBJECT
orAbstractStreamDecoder.TokenType.START_ARRAY
, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECT
orAbstractStreamDecoder.TokenType.END_ARRAY
.Methods inherited from class io.micronaut.serde.support.AbstractDecoderPerStructureStreamDecoder
decodeArray0, decodeKey, decodeObject0, finishStructure, hasNextArrayValue, preDecodeValue
Methods 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, 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, 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:AbstractDecoderPerStructureStreamDecoder
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.- Overrides:
backFromChild
in classAbstractDecoderPerStructureStreamDecoder
- Parameters:
child
- The now-invalid child decoder.- Throws:
IOException
- if an unrecoverable error occurs
-
nextToken
protected void nextToken()Description copied from class:AbstractStreamDecoder
Move to the next token.- Specified by:
nextToken
in classAbstractStreamDecoder
-
getCurrentKey
Description copied from class:AbstractStreamDecoder
Get the current object field name. Only called forAbstractStreamDecoder.TokenType.KEY
.- Specified by:
getCurrentKey
in classAbstractStreamDecoder
- Returns:
- The current field key
-
coerceScalarToString
protected String coerceScalarToString(AbstractStreamDecoder.TokenType currentToken) throws IOException Description copied from class:AbstractStreamDecoder
Decode any non-null scalar value (number, string or boolean) to its string representation.- Specified by:
coerceScalarToString
in 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:AbstractDecoderPerStructureStreamDecoder
Create a new child decoder usingAbstractDecoderPerStructureStreamDecoder(AbstractDecoderPerStructureStreamDecoder,io.micronaut.serde.LimitingStream.RemainingLimits)
.- Specified by:
createChildDecoder
in classAbstractDecoderPerStructureStreamDecoder
- Returns:
- The new decoder
- Throws:
SerdeException
-
getString
Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.STRING
value. Called for no other token type.- Specified by:
getString
in classAbstractStreamDecoder
- Returns:
- The String value
-
getBoolean
protected boolean getBoolean()Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.BOOLEAN
value. Called for no other token type.- Specified by:
getBoolean
in classAbstractStreamDecoder
- Returns:
- The boolean value
-
getLong
protected long getLong()Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as a long value. Called for no other token type.- Specified by:
getLong
in classAbstractStreamDecoder
- Returns:
- The number value
-
getDouble
protected double getDouble()Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as a double value. Called for no other token type.- Specified by:
getDouble
in classAbstractStreamDecoder
- Returns:
- The number value
-
getBigInteger
Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aBigInteger
value. Called for no other token type.- Specified by:
getBigInteger
in classAbstractStreamDecoder
- Returns:
- The number value
-
getBigDecimal
Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aBigDecimal
value. Called for no other token type.- Specified by:
getBigDecimal
in classAbstractStreamDecoder
- Returns:
- The number value
-
getBestNumber
Description copied from class:AbstractStreamDecoder
Decode the currentAbstractStreamDecoder.TokenType.NUMBER
value as aNumber
value. Called for no other token type.- Specified by:
getBestNumber
in classAbstractStreamDecoder
- Returns:
- The number value
-
getBigDecimalFromNumber
Description copied from class:AbstractStreamDecoder
Converts the number, probably retrieved by callingAbstractStreamDecoder.getBestNumber()
, to aBigDecimal
.- Overrides:
getBigDecimalFromNumber
in classAbstractStreamDecoder
- Parameters:
number
- The number value- Returns:
- The number as a big decimal
-
decodeBinary
Description copied from interface:Decoder
Decode 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:
decodeBinary
in interfaceDecoder
- Overrides:
decodeBinary
in classAbstractStreamDecoder
- Returns:
- The decoded byte array
- Throws:
IOException
-
skipChildren
protected void skipChildren()Description copied from class:AbstractStreamDecoder
If we are at aAbstractStreamDecoder.TokenType.START_OBJECT
orAbstractStreamDecoder.TokenType.START_ARRAY
, skip to the matchingAbstractStreamDecoder.TokenType.END_OBJECT
orAbstractStreamDecoder.TokenType.END_ARRAY
. Else, do nothing.- Specified by:
skipChildren
in classAbstractStreamDecoder
-
currentToken
- Specified by:
currentToken
in classAbstractStreamDecoder
- Returns:
- The current token.
-
createDeserializationException
Description copied from interface:Decoder
Creates an exception for the given message.- Parameters:
message
- The message, nevernull
invalidValue
- 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:Decoder
Buffer the whole subtree of this value and return it as a newDecoder
. The returnedDecoder
can be used independently to thisDecoder
. This means actual parsing of the subtree can be delayed.The returned
Decoder
should behave identically to thisDecoder
. This means that for exampledecoder.decodeDouble()
should be equivalent todecoder.decodeBuffer().decodeDouble()
.- Specified by:
decodeBuffer
in interfaceDecoder
- Overrides:
decodeBuffer
in classAbstractStreamDecoder
- Returns:
- An independent decoder that visits this subtree.
- Throws:
IOException
- If an unrecoverable error occurs
-