Package io.micronaut.json.codec
Class MapperMediaTypeCodec
java.lang.Object
io.micronaut.json.codec.MapperMediaTypeCodec
- All Implemented Interfaces:
MediaTypeCodec
- Direct Known Subclasses:
JacksonMediaTypeCodec
,JsonMediaTypeCodec
A
MediaTypeCodec
for JsonMapper
based implementations.- Since:
- 1.3.0
- Author:
- Graeme Rocher, svishnyakov
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ApplicationConfiguration
protected final CodecConfiguration
protected final MediaType
static final String
-
Constructor Summary
ConstructorDescriptionMapperMediaTypeCodec
(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType) MapperMediaTypeCodec
(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType, @Nullable List<MediaType> additionalTypes) MapperMediaTypeCodec
(JsonMapper mapper, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType) -
Method Summary
Modifier and TypeMethodDescriptioncloneWithFeatures
(JsonFeatures features) Create a copy of this codec with the given features.protected abstract MapperMediaTypeCodec
cloneWithMapper
(JsonMapper mapper) final MapperMediaTypeCodec
cloneWithViewClass
(Class<?> viewClass) <T> T
Decode the given type from the given bytes.<T> T
decode
(Argument<T> type, ByteBuffer<?> buffer) Decode the given type from the given buffer.<T> T
Decodes the given JSON node.<T> T
decode
(Argument<T> type, InputStream inputStream) Decode the given type from the givenInputStream
.<T> T
Decode the given type from the given bytes.<T> byte[]
Encode the given type returning the object as a byte[].<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
.<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
.boolean
supportsType
(Class<?> type) Whether the codec can decode the given type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.http.codec.MediaTypeCodec
decode, decode, decode, decode
-
Field Details
-
REGULAR_JSON_MEDIA_TYPE_CODEC_NAME
- See Also:
-
applicationConfiguration
-
additionalTypes
-
codecConfiguration
-
mediaType
-
-
Constructor Details
-
MapperMediaTypeCodec
public MapperMediaTypeCodec(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType) - Parameters:
mapperProvider
- To read/write JSONapplicationConfiguration
- The common application configurationscodecConfiguration
- The configuration for the codecmediaType
- Client request/response media type
-
MapperMediaTypeCodec
public MapperMediaTypeCodec(BeanProvider<JsonMapper> mapperProvider, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType, @Nullable @Nullable List<MediaType> additionalTypes) - Parameters:
mapperProvider
- To read/write JSONapplicationConfiguration
- The common application configurationscodecConfiguration
- The configuration for the codecmediaType
- Client request/response media typeadditionalTypes
- Additional Media Types
-
MapperMediaTypeCodec
public MapperMediaTypeCodec(JsonMapper mapper, ApplicationConfiguration applicationConfiguration, CodecConfiguration codecConfiguration, MediaType mediaType) - Parameters:
mapper
- To read/write JSONapplicationConfiguration
- The common application configurationscodecConfiguration
- The configuration for the codecmediaType
- Client request/response media type
-
-
Method Details
-
getJsonMapper
- Returns:
- The object mapper
-
cloneWithFeatures
Create a copy of this codec with the given features. Should not be extended, extendcloneWithMapper(io.micronaut.json.JsonMapper)
instead.- Parameters:
features
- The features to apply.- Returns:
- A new codec with the features applied, leaving this codec unchanged.
-
cloneWithViewClass
-
cloneWithMapper
-
getMediaTypes
- Specified by:
getMediaTypes
in interfaceMediaTypeCodec
- Returns:
- The media type of the codec
-
supportsType
Description copied from interface:MediaTypeCodec
Whether the codec can decode the given type.- Specified by:
supportsType
in interfaceMediaTypeCodec
- Parameters:
type
- The type- Returns:
- True if it can
-
decode
Description copied from interface:MediaTypeCodec
Decode the given type from the givenInputStream
.- Specified by:
decode
in interfaceMediaTypeCodec
- 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
Decodes the given JSON node.- Type Parameters:
T
- The generic type- Parameters:
type
- The typenode
- The Json Node- Returns:
- The decoded object
- Throws:
CodecException
- When object cannot be decoded
-
decode
Description copied from interface:MediaTypeCodec
Decode the given type from the given buffer. Implementations optimized to handleByteBuffer
instances should override this method.- Specified by:
decode
in interfaceMediaTypeCodec
- 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
Description copied from interface:MediaTypeCodec
Decode the given type from the given bytes.- Specified by:
decode
in interfaceMediaTypeCodec
- 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
Description copied from interface:MediaTypeCodec
Decode the given type from the given bytes.- Specified by:
decode
in interfaceMediaTypeCodec
- 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
-
encode
Description copied from interface:MediaTypeCodec
Encode the given type to the givenOutputStream
.- Specified by:
encode
in interfaceMediaTypeCodec
- Type Parameters:
T
- The generic type- Parameters:
object
- The object to encodeoutputStream
- The output stream- Throws:
CodecException
- When the result cannot be encoded
-
encode
public <T> void encode(@NonNull @NonNull Argument<T> type, @NonNull T object, @NonNull @NonNull OutputStream outputStream) throws CodecException Description copied from interface:MediaTypeCodec
Encode the given type to the givenOutputStream
.- Specified by:
encode
in interfaceMediaTypeCodec
- 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
-
encode
Description copied from interface:MediaTypeCodec
Encode the given type returning the object as a byte[].- Specified by:
encode
in interfaceMediaTypeCodec
- 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
Description copied from interface:MediaTypeCodec
Encode the given type returning the object as a byte[].- Specified by:
encode
in interfaceMediaTypeCodec
- 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
-
encode
public <T,B> ByteBuffer<B> encode(T object, ByteBufferFactory<?, B> allocator) throws CodecExceptionDescription copied from interface:MediaTypeCodec
Encode the given type returning the object as aByteBuffer
.- Specified by:
encode
in interfaceMediaTypeCodec
- 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
@NonNull public <T,B> @NonNull ByteBuffer<B> encode(@NonNull @NonNull Argument<T> type, T object, @NonNull @NonNull ByteBufferFactory<?, B> allocator) throws CodecExceptionDescription copied from interface:MediaTypeCodec
Encode the given type returning the object as aByteBuffer
.- Specified by:
encode
in interfaceMediaTypeCodec
- 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
-