Package io.micronaut.http.netty.body
Class NettyJsonHandler<T>
java.lang.Object
io.micronaut.http.netty.body.NettyJsonHandler<T>
- Type Parameters:
T
- The type
- All Implemented Interfaces:
ChunkedMessageBodyReader<T>
,MessageBodyHandler<T>
,MessageBodyReader<T>
,MessageBodyWriter<T>
,CustomizableNettyJsonHandler
@Singleton
@Internal
@Replaces(JsonMessageHandler.class)
@Produces({"application/json","text/json","application/hal+json","application/vnd.github+json","application/feed+json","application/json-patch+json","application/merge-patch+json","application/problem+json"})
@Consumes({"application/json","text/json","application/hal+json","application/vnd.github+json","application/feed+json","application/json-patch+json","application/merge-patch+json","application/problem+json"})
@Requires(beans=JsonMapper.class)
public final class NettyJsonHandler<T>
extends Object
implements MessageBodyHandler<T>, ChunkedMessageBodyReader<T>, CustomizableNettyJsonHandler
Replacement for
JsonMessageHandler
with ChunkedMessageBodyReader
support.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific
(Argument<T> type) Prepare aMessageBodyWriter
that will write the given type.customize
(JsonFeatures jsonFeatures) boolean
true
iff this closure can do a blocking read on the object it receives.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.readChunked
(Argument<T> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) ByteBuffer<?>
writeTo
(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, ByteBufferFactory<?, ?> bufferFactory) Writes an object to the given stream.void
writeTo
(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, OutputStream outputStream) Writes an object to the given output stream.
-
Constructor Details
-
NettyJsonHandler
-
-
Method Details
-
customize
- Specified by:
customize
in interfaceCustomizableNettyJsonHandler
-
readChunked
public Publisher<T> readChunked(Argument<T> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) - Specified by:
readChunked
in interfaceChunkedMessageBodyReader<T>
-
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
-
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
-
writeTo
public ByteBuffer<?> writeTo(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, ByteBufferFactory<?, ?> bufferFactory) throws CodecExceptionDescription copied from interface:MessageBodyWriter
Writes an object to the given stream.- Specified by:
writeTo
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media typeobject
- The object to writeoutgoingHeaders
- The HTTP headersbufferFactory
- A byte buffer factory- Returns:
- The encoded byte buffer
- Throws:
CodecException
- If an error occurs decoding
-
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
-
isBlocking
public boolean isBlocking()Description copied from interface:MessageBodyWriter
true
iff this closure can do a blocking read on the object it receives. For example, if this closure writes from anInputStream
, that operation may be blocking and this method returnstrue
.
Note that even when this isfalse
,MessageBodyWriter.writeTo(Argument, MediaType, Object, MutableHeaders, OutputStream)
may still block because theOutputStream
that is passed as the write destination may still block.- Specified by:
isBlocking
in interfaceMessageBodyWriter<T>
- Returns:
- Whether this writer may block
-