Interface Decoder

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
AbstractDecoderPerStructureStreamDecoder, AbstractStreamDecoder, BsonReaderDecoder, DelegatingDecoder, JacksonDecoder, JsonNodeDecoder, JsonParserDecoder, OracleJdbcJsonParserDecoder

public interface Decoder extends AutoCloseable
Core interface for decoding values from a serialized format such as JSON.
Since:
1.0.0
  • Method Details

    • decodeArray

      @NonNull @NonNull Decoder decodeArray(io.micronaut.core.type.Argument<?> type) throws IOException
      Start decoding an array.
      Parameters:
      type - The array type
      Returns:
      The array decoder
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeArray

      @NonNull default @NonNull Decoder decodeArray() throws IOException
      Start decoding an array.
      Returns:
      The array decoder
      Throws:
      IOException - If an unrecoverable error occurs
    • hasNextArrayValue

      boolean hasNextArrayValue() throws IOException
      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, never null
      Returns:
      The object decoder
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeObject

      @NonNull default @NonNull Decoder decodeObject() throws IOException
      Decodes an object.
      Returns:
      The object decoder
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeKey

      @Nullable @Nullable String decodeKey() throws IOException
      Decodes a key, if there are no more keys to decode returns null.
      Returns:
      The key or null if there aren't any more keys
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeString

      @NonNull @NonNull String decodeString() throws IOException
      Decodes a string.
      Returns:
      The string, never null
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeStringNullable

      @Nullable default @Nullable String decodeStringNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeString().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBoolean

      boolean decodeBoolean() throws IOException
      Decodes a boolean.
      Returns:
      The boolean
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBooleanNullable

      @Nullable default @Nullable Boolean decodeBooleanNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeBoolean().
      Returns:
      The boolean
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeByte

      byte decodeByte() throws IOException
      Decodes a byte.
      Returns:
      The byte
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeByteNullable

      @Nullable default @Nullable Byte decodeByteNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeByte().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeShort

      short decodeShort() throws IOException
      Decodes a short.
      Returns:
      The short
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeShortNullable

      @Nullable default @Nullable Short decodeShortNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeShort().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeChar

      char decodeChar() throws IOException
      Decodes a char.
      Returns:
      The char
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeCharNullable

      @Nullable default @Nullable Character decodeCharNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeChar().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeNumber

      default Number decodeNumber() throws IOException
      Decodes a number.
      Returns:
      The number
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      2.9.0
    • decodeNumberNullable

      @Nullable default @Nullable Number decodeNumberNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeNumber().
      Returns:
      The number
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      2.9.0
    • decodeInt

      int decodeInt() throws IOException
      Decodes a int.
      Returns:
      The int
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeIntNullable

      @Nullable default @Nullable Integer decodeIntNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeInt().
      Returns:
      The int
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeLong

      long decodeLong() throws IOException
      Decodes a long.
      Returns:
      The long
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeLongNullable

      @Nullable default @Nullable Long decodeLongNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeLong().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeFloat

      float decodeFloat() throws IOException
      Decodes a float.
      Returns:
      The float
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeFloatNullable

      @Nullable default @Nullable Float decodeFloatNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeFloat().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeDouble

      double decodeDouble() throws IOException
      Decodes a double.
      Returns:
      The double
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeDoubleNullable

      @Nullable default @Nullable Double decodeDoubleNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeDouble().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBigInteger

      @NonNull @NonNull BigInteger decodeBigInteger() throws IOException
      Decodes a BigInteger.
      Returns:
      The BigInteger, never null
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBigIntegerNullable

      @Nullable default @Nullable BigInteger decodeBigIntegerNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeBigInteger().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBigDecimal

      @NonNull @NonNull BigDecimal decodeBigDecimal() throws IOException
      Decodes a BigDecimal.
      Returns:
      The BigDecimal, never null
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBigDecimalNullable

      @Nullable default @Nullable BigDecimal decodeBigDecimalNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeBigDecimal().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBinary

      default byte @NonNull [] decodeBinary() throws IOException
      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.
      Implementations must support the array shape, but the other shapes are optional.
      Returns:
      The decoded byte array
      Throws:
      IOException
      Since:
      2.1
    • decodeBinaryNullable

      default byte @Nullable [] decodeBinaryNullable() throws IOException
      Equivalent to decodeNull() ? null : decodeBinary().
      Returns:
      The value
      Throws:
      IOException - If an unrecoverable error occurs
      Since:
      2.1
    • decodeNull

      boolean decodeNull() throws IOException
      Attempt to decode a null value. Returns false if this value is not null, and another method should be used for decoding. Returns true if this value was null, and the cursor has been advanced to the next value.
      Returns:
      Returns true if the value was null
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeArbitrary

      @Nullable @Nullable Object decodeArbitrary() throws IOException
      Decodes the current state into an arbitrary object.

      The following should be decoded by this method:

      • Object types will be decoded into a Map
      • Array types will be decoded into a List
      • JSON primitive types into the equivalent Java wrapper type
      Returns:
      The decoded object
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeNode

      @NonNull @NonNull io.micronaut.json.tree.JsonNode decodeNode() throws IOException
      Decodes the current state into a JsonNode.
      Returns:
      The decoded node
      Throws:
      IOException - If an unrecoverable error occurs
    • decodeBuffer

      Decoder decodeBuffer() throws IOException
      Buffer the whole subtree of this value and return it as a new Decoder. The returned Decoder can be used independently to this Decoder. This means actual parsing of the subtree can be delayed.

      The returned Decoder should behave identically to this Decoder. This means that for example decoder.decodeDouble() should be equivalent to decoder.decodeBuffer().decodeDouble().

      Returns:
      An independent decoder that visits this subtree.
      Throws:
      IOException - If an unrecoverable error occurs
    • skipValue

      void skipValue() throws IOException
      Skips the current value.
      Throws:
      IOException - If an unrecoverable error occurs
    • finishStructure

      default void finishStructure() throws IOException
      Throws:
      IllegalStateException - If there are still elements left to consume
      IOException - If an unrecoverable error occurs
    • finishStructure

      void finishStructure(boolean consumeLeftElements) throws IOException
      Parameters:
      consumeLeftElements - True to consume left elements
      Throws:
      IllegalStateException - If there are still elements left to consume and consumeLeftElements is false
      IOException - If an unrecoverable error occurs
    • close

      default void close() throws IOException
      Finalize the current structure. Equivalent to calling finishStructure().
      Specified by:
      close in interface AutoCloseable
      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, never null
      invalidValue - The invalid value. Can be null.
      Returns:
      The exception, never null