Package io.micronaut.http.codec
Interface MediaTypeCodec
- All Known Implementing Classes:
JacksonMediaTypeCodec
,JsonMediaTypeCodec
,JsonMediaTypeCodec
,JsonStreamMediaTypeCodec
,JsonStreamMediaTypeCodec
,MapperMediaTypeCodec
,TextPlainCodec
,TextStreamCodec
Represents a codec for a particular media type. For example JSON.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> T
Decode the given type from the given bytes.default <T> T
decode
(Argument<T> type, ByteBuffer<?> buffer) Decode the given type from the given buffer.<T> T
decode
(Argument<T> type, InputStream inputStream) Decode the given type from the givenInputStream
.default <T> T
Decode the given type from the given bytes.default <T> T
Decode the given type from the given bytes.default <T> T
decode
(Class<T> type, ByteBuffer<?> buffer) Decode the given type from the given buffer.default <T> T
decode
(Class<T> type, InputStream inputStream) Decode the given type from the givenInputStream
.default <T> T
Decode the given type from the given bytes.default <T> @io.micronaut.core.annotation.NonNull byte[]
Encode the given type returning the object as a byte[].default <T,
B> @NonNull ByteBuffer<B> encode
(@NonNull Argument<T> type, T object, @NonNull ByteBufferFactory<?, B> allocator) Encode the given type returning the object as aByteBuffer
.default <T> void
encode
(@NonNull Argument<T> type, T object, @NonNull OutputStream outputStream) Encode the given type to the givenOutputStream
.<T> byte[]
encode
(T object) Encode the given type returning the object as a byte[].<T,
B> ByteBuffer<B> encode
(T object, ByteBufferFactory<?, B> allocator) Encode the given type returning the object as aByteBuffer
.<T> void
encode
(T object, OutputStream outputStream) Encode the given type to the givenOutputStream
.default boolean
supportsType
(Class<?> type) Whether the codec can decode the given type.
-
Method Details
-
getMediaTypes
Collection<MediaType> getMediaTypes()- Returns:
- The media type of the codec
-
decode
Decode the given type from the givenInputStream
.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeinputStream
- The input stream- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
encode
Encode the given type to the givenOutputStream
.- Type Parameters:
T
- The generic type- Parameters:
object
- The object to encodeoutputStream
- The output stream- Throws:
CodecException
- When the result cannot be encoded
-
encode
Encode the given type returning the object as a byte[].- Type Parameters:
T
- The generic type- Parameters:
object
- The object to encode- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be encoded
-
encode
Encode the given type returning the object as aByteBuffer
.- Type Parameters:
T
- The generic typeB
- The buffer type- Parameters:
object
- The object to encodeallocator
- The allocator- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be encoded
-
encode
default <T> void encode(@NonNull @NonNull Argument<T> type, @NonNull T object, @NonNull @NonNull OutputStream outputStream) throws CodecException Encode the given type to the givenOutputStream
.- Type Parameters:
T
- The generic type- Parameters:
type
- The type including any generics and/or metadata.object
- The object to encodeoutputStream
- The output stream- Throws:
CodecException
- When the result cannot be encoded- Since:
- 3.2.0
-
encode
@NonNull default <T> @io.micronaut.core.annotation.NonNull byte[] encode(@NonNull @NonNull Argument<T> type, T object) throws CodecException Encode the given type returning the object as a byte[].- Type Parameters:
T
- The generic type- Parameters:
type
- The type including any generics and/or metadataobject
- The object to encode- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be encoded- Since:
- 3.2.0
-
encode
@NonNull default <T,B> @NonNull ByteBuffer<B> encode(@NonNull @NonNull Argument<T> type, T object, @NonNull @NonNull ByteBufferFactory<?, B> allocator) throws CodecExceptionEncode the given type returning the object as aByteBuffer
.- Type Parameters:
T
- The generic typeB
- The buffer type- Parameters:
type
- The type including any generics and/or metadataobject
- The object to encodeallocator
- The allocator- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be encoded- Since:
- 3.2.0
-
decode
Decode the given type from the givenInputStream
.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeinputStream
- The input stream- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given bytes.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typebytes
- The bytes- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given bytes.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typebytes
- The bytes- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given buffer. Implementations optimized to handleByteBuffer
instances should override this method.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typebuffer
- the buffer- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given buffer. Implementations optimized to handleByteBuffer
instances should override this method.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typebuffer
- the buffer- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given bytes.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typedata
- The data as a string- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
decode
Decode the given type from the given bytes.- Type Parameters:
T
- The decoded type- Parameters:
type
- The typedata
- The data as a string- Returns:
- The decoded result
- Throws:
CodecException
- When the result cannot be decoded
-
supportsType
Whether the codec can decode the given type.- Parameters:
type
- The type- Returns:
- True if it can
-