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 voidclose()Finalize the current structure.@NonNull IOExceptioncreateDeserializationException(@NonNull String message, @Nullable Object invalidValue) Creates an exception for the given message.@Nullable ObjectDecodes the current state into an arbitrary object.default @NonNull DecoderStart decoding an array.@NonNull DecoderdecodeArray(io.micronaut.core.type.Argument<?> type) Start decoding an array.@NonNull BigDecimalDecodes a BigDecimal.default @Nullable BigDecimalEquivalent todecodeNull() ? null : decodeBigDecimal().@NonNull BigIntegerDecodes a BigInteger.default @Nullable BigIntegerEquivalent todecodeNull() ? null : decodeBigInteger().default byte @NonNull []Decode binary data from this stream.default byte @Nullable []Equivalent todecodeNull() ? null : decodeBinary().booleanDecodes a boolean.default @Nullable BooleanEquivalent todecodeNull() ? null : decodeBoolean().Buffer the whole subtree of this value and return it as a newDecoder.byteDecodes a byte.default @Nullable ByteEquivalent todecodeNull() ? null : decodeByte().charDecodes a char.default @Nullable CharacterEquivalent todecodeNull() ? null : decodeChar().doubleDecodes a double.default @Nullable DoubleEquivalent todecodeNull() ? null : decodeDouble().floatDecodes a float.default @Nullable FloatEquivalent todecodeNull() ? null : decodeFloat().intDecodes a int.default @Nullable IntegerEquivalent todecodeNull() ? null : decodeInt().@Nullable StringDecodes a key, if there are no more keys to decode returnsnull.longDecodes a long.default @Nullable LongEquivalent todecodeNull() ? null : decodeLong().@NonNull io.micronaut.json.tree.JsonNodeDecodes the current state into aJsonNode.booleanAttempt to decode a null value.default NumberDecodes a number.default @Nullable NumberEquivalent todecodeNull() ? null : decodeNumber().default @NonNull DecoderDecodes an object.@NonNull DecoderdecodeObject(@NonNull io.micronaut.core.type.Argument<?> type) Decodes an object.shortDecodes a short.default @Nullable ShortEquivalent todecodeNull() ? null : decodeShort().@NonNull StringDecodes a string.default @Nullable StringEquivalent todecodeNull() ? null : decodeString().default voidvoidfinishStructure(boolean consumeLeftElements) booleanvoidSkips 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
trueif 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
nullif 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. Returnsfalseif this value is not null, and another method should be used for decoding. Returnstrueif this value was null, and the cursor has been advanced to the next value.- Returns:
- Returns
trueif 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 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().- 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:
closein 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, nevernullinvalidValue- The invalid value. Can benull.- Returns:
- The exception, never
null
-