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>
,NettyBodyWriter<T>
,CustomizableJsonHandler
@Order(-10)
@Singleton
@Internal
@Replaces(JsonMessageHandler.class)
@ProducesJson
@ConsumesJson
@Requires(beans=JsonMapper.class)
public final class NettyJsonHandler<T>
extends Object
implements MessageBodyHandler<T>, ChunkedMessageBodyReader<T>, CustomizableJsonHandler, NettyBodyWriter<T>
Replacement for
JsonMessageHandler
with ChunkedMessageBodyReader
support.-
Constructor Summary
-
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) void
writeTo
(@NonNull HttpRequest<?> request, @NonNull MutableHttpResponse<T> outgoingResponse, @NonNull Argument<T> type, @NonNull MediaType mediaType, T object, @NonNull NettyWriteContext nettyContext) Write an object to the given context.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 interfaceCustomizableJsonHandler
-
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
-
writeTo
public void writeTo(@NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<T> outgoingResponse, @NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, @NonNull T object, @NonNull @NonNull NettyWriteContext nettyContext) throws CodecException Description copied from interface:NettyBodyWriter
Write an object to the given context.- Specified by:
writeTo
in interfaceNettyBodyWriter<T>
- Parameters:
request
- The associated requestoutgoingResponse
- The outgoing response.type
- The typemediaType
- The media typeobject
- The object to writenettyContext
- The netty context- 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
-