Package io.micronaut.json.body
Class JsonMessageHandler<T>
java.lang.Object
io.micronaut.json.body.JsonMessageHandler<T>
- Type Parameters:
T
- The type to read/write
- All Implemented Interfaces:
MessageBodyHandler<T>
,MessageBodyReader<T>
,MessageBodyWriter<T>
@Singleton
@Produces({"application/json","text/json","application/hal+json","application/vnd.github+json","application/feed+json","application/problem+json"})
@Consumes({"application/json","text/json","application/hal+json","application/vnd.github+json","application/feed+json","application/problem+json"})
public final class JsonMessageHandler<T>
extends Object
implements MessageBodyHandler<T>
Body handler for JSON.
- Since:
- 4.0.0
- Author:
- Jonas Konrad
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific
(Argument<T> type) Prepare aMessageBodyWriter
that will write the given type.Get the json mapper used by this handler.boolean
isReadable
(Argument<T> type, MediaType mediaType) Is the type readable.boolean
isWriteable
(Argument<T> type, MediaType mediaType) Is the type writeable.Reads an object from the given byte buffer.Reads an object from the given byte buffer.void
writeTo
(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, OutputStream outputStream) Writes an object to the given output stream.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.body.MessageBodyWriter
isBlocking, writeTo
-
Constructor Details
-
JsonMessageHandler
-
-
Method Details
-
getJsonMapper
Get the json mapper used by this handler.- Returns:
- The mapper
-
isReadable
Description copied from interface:MessageBodyReader
Is the type readable.- Specified by:
isReadable
in interfaceMessageBodyReader<T>
- Parameters:
type
- The typemediaType
- The media type, can benull
- Returns:
- True if is readable
-
createSpecific
Description copied from interface:MessageBodyWriter
Prepare aMessageBodyWriter
that will write the given type. This can be used for precomputing some route data.- Specified by:
createSpecific
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The type- Returns:
- The closure
-
read
public T read(Argument<T> type, MediaType mediaType, Headers httpHeaders, ByteBuffer<?> byteBuffer) throws CodecException Description copied from interface:MessageBodyReader
Reads an object from the given byte buffer.- Specified by:
read
in interfaceMessageBodyReader<T>
- Parameters:
type
- The type being decoded.mediaType
- The media type, can benull
httpHeaders
- The HTTP headersbyteBuffer
- The byte buffer- Returns:
- The read object or
null
- Throws:
CodecException
- If an error occurs decoding
-
read
public T read(Argument<T> type, MediaType mediaType, Headers httpHeaders, InputStream inputStream) throws CodecException Description copied from interface:MessageBodyReader
Reads an object from the given byte buffer.- Specified by:
read
in interfaceMessageBodyReader<T>
- Parameters:
type
- The type being decoded.mediaType
- The media type, can benull
httpHeaders
- The HTTP headersinputStream
- The input stream- Returns:
- The read object or
null
- Throws:
CodecException
- If an error occurs decoding
-
isWriteable
Description copied from interface:MessageBodyWriter
Is the type writeable.- Specified by:
isWriteable
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media type, can benull
- Returns:
- True if is writable
-
writeTo
public void writeTo(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, OutputStream outputStream) throws CodecException Description copied from interface:MessageBodyWriter
Writes an object to the given output stream.- Specified by:
writeTo
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media typeobject
- The object to writeoutgoingHeaders
- The HTTP headersoutputStream
- The output stream- Throws:
CodecException
- If an error occurs decoding
-