Package io.micronaut.serde
Interface Decoder
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractDecoderPerStructureStreamDecoder
,AbstractStreamDecoder
,BsonReaderDecoder
,DelegatingDecoder
,JacksonDecoder
,JsonNodeDecoder
,JsonParserDecoder
,OracleJdbcJsonParserDecoder
Core interface for decoding values from a serialized format such as JSON.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
Finalize the current structure.@NonNull IOException
createDeserializationException
(@NonNull String message, @Nullable Object invalidValue) Creates an exception for the given message.@Nullable Object
Decodes the current state into an arbitrary object.default @NonNull Decoder
Start decoding an array.@NonNull Decoder
decodeArray
(io.micronaut.core.type.Argument<?> type) Start decoding an array.@NonNull BigDecimal
Decodes a BigDecimal.default @Nullable BigDecimal
Equivalent todecodeNull() ? null : decodeBigDecimal()
.@NonNull BigInteger
Decodes a BigInteger.default @Nullable BigInteger
Equivalent todecodeNull() ? null : decodeBigInteger()
.default byte @NonNull []
Decode binary data from this stream.default byte @Nullable []
Equivalent todecodeNull() ? null : decodeBinary()
.boolean
Decodes a boolean.default @Nullable Boolean
Equivalent todecodeNull() ? null : decodeBoolean()
.Buffer the whole subtree of this value and return it as a newDecoder
.byte
Decodes a byte.default @Nullable Byte
Equivalent todecodeNull() ? null : decodeByte()
.char
Decodes a char.default @Nullable Character
Equivalent todecodeNull() ? null : decodeChar()
.double
Decodes a double.default @Nullable Double
Equivalent todecodeNull() ? null : decodeDouble()
.float
Decodes a float.default @Nullable Float
Equivalent todecodeNull() ? null : decodeFloat()
.int
Decodes a int.default @Nullable Integer
Equivalent todecodeNull() ? null : decodeInt()
.@Nullable String
Decodes a key, if there are no more keys to decode returnsnull
.long
Decodes a long.default @Nullable Long
Equivalent todecodeNull() ? null : decodeLong()
.@NonNull io.micronaut.json.tree.JsonNode
Decodes the current state into aJsonNode
.boolean
Attempt to decode a null value.default Number
Decodes a number.default @Nullable Number
Equivalent todecodeNull() ? null : decodeNumber()
.default @NonNull Decoder
Decodes an object.@NonNull Decoder
decodeObject
(@NonNull io.micronaut.core.type.Argument<?> type) Decodes an object.short
Decodes a short.default @Nullable Short
Equivalent todecodeNull() ? null : decodeShort()
.@NonNull String
Decodes a string.default @Nullable String
Equivalent todecodeNull() ? null : decodeString()
.default void
void
finishStructure
(boolean consumeLeftElements) boolean
void
Skips the current value.
-
Method Details
-
decodeArray
Start decoding an array.- Parameters:
type
- The array type- Returns:
- The array decoder
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeArray
Start decoding an array.- Returns:
- The array decoder
- Throws:
IOException
- If an unrecoverable error occurs
-
hasNextArrayValue
- Returns:
- Returns
true
if another array value is available. - Throws:
IOException
- If an unrecoverable error occurs
-
decodeObject
@NonNull @NonNull Decoder decodeObject(@NonNull @NonNull io.micronaut.core.type.Argument<?> type) throws IOException Decodes an object.- Parameters:
type
- The type, nevernull
- Returns:
- The object decoder
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeObject
Decodes an object.- Returns:
- The object decoder
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeKey
Decodes a key, if there are no more keys to decode returnsnull
.- Returns:
- The key or
null
if there aren't any more keys - Throws:
IOException
- If an unrecoverable error occurs
-
decodeString
Decodes a string.- Returns:
- The string, never
null
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeStringNullable
Equivalent todecodeNull() ? null : decodeString()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBoolean
Decodes a boolean.- Returns:
- The boolean
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBooleanNullable
Equivalent todecodeNull() ? null : decodeBoolean()
.- Returns:
- The boolean
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeByte
Decodes a byte.- Returns:
- The byte
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeByteNullable
Equivalent todecodeNull() ? null : decodeByte()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeShort
Decodes a short.- Returns:
- The short
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeShortNullable
Equivalent todecodeNull() ? null : decodeShort()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeChar
Decodes a char.- Returns:
- The char
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeCharNullable
Equivalent todecodeNull() ? null : decodeChar()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeNumber
Decodes a number.- Returns:
- The number
- Throws:
IOException
- If an unrecoverable error occurs- Since:
- 2.9.0
-
decodeNumberNullable
Equivalent todecodeNull() ? null : decodeNumber()
.- Returns:
- The number
- Throws:
IOException
- If an unrecoverable error occurs- Since:
- 2.9.0
-
decodeInt
Decodes a int.- Returns:
- The int
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeIntNullable
Equivalent todecodeNull() ? null : decodeInt()
.- Returns:
- The int
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeLong
Decodes a long.- Returns:
- The long
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeLongNullable
Equivalent todecodeNull() ? null : decodeLong()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeFloat
Decodes a float.- Returns:
- The float
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeFloatNullable
Equivalent todecodeNull() ? null : decodeFloat()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeDouble
Decodes a double.- Returns:
- The double
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeDoubleNullable
Equivalent todecodeNull() ? null : decodeDouble()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBigInteger
Decodes a BigInteger.- Returns:
- The BigInteger, never
null
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBigIntegerNullable
Equivalent todecodeNull() ? null : decodeBigInteger()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBigDecimal
Decodes a BigDecimal.- Returns:
- The BigDecimal, never
null
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBigDecimalNullable
Equivalent todecodeNull() ? null : decodeBigDecimal()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBinary
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.
- Returns:
- The decoded byte array
- Throws:
IOException
- Since:
- 2.1
-
decodeBinaryNullable
Equivalent todecodeNull() ? null : decodeBinary()
.- Returns:
- The value
- Throws:
IOException
- If an unrecoverable error occurs- Since:
- 2.1
-
decodeNull
Attempt to decode a null value. Returnsfalse
if this value is not null, and another method should be used for decoding. Returnstrue
if this value was null, and the cursor has been advanced to the next value.- Returns:
- Returns
true
if the value wasnull
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeArbitrary
Decodes the current state into an arbitrary object.The following should be decoded by this method:
- Returns:
- The decoded object
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeNode
Decodes the current state into aJsonNode
.- Returns:
- The decoded node
- Throws:
IOException
- If an unrecoverable error occurs
-
decodeBuffer
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()
.- Returns:
- An independent decoder that visits this subtree.
- Throws:
IOException
- If an unrecoverable error occurs
-
skipValue
Skips the current value.- Throws:
IOException
- If an unrecoverable error occurs
-
finishStructure
- Throws:
IllegalStateException
- If there are still elements left to consumeIOException
- If an unrecoverable error occurs
-
finishStructure
- Parameters:
consumeLeftElements
- True to consume left elements- Throws:
IllegalStateException
- If there are still elements left to consume and consumeLeftElements is falseIOException
- If an unrecoverable error occurs
-
close
Finalize the current structure. Equivalent to callingfinishStructure()
.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- If an unrecoverable error occurs
-
createDeserializationException
@NonNull @NonNull IOException createDeserializationException(@NonNull @NonNull String message, @Nullable @Nullable Object invalidValue) Creates an exception for the given message.- Parameters:
message
- The message, nevernull
invalidValue
- The invalid value. Can benull
.- Returns:
- The exception, never
null
-