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>,ResponseBodyWriter<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, ResponseBodyWriter<T>
Replacement for
JsonMessageHandler with ChunkedMessageBodyReader support.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific(Argument<T> type) Prepare aMessageBodyWriterthat will write the given type.customize(JsonFeatures jsonFeatures) booleantrueiff this closure can do a blocking read on the object it receives.booleanisReadable(Argument<T> type, MediaType mediaType) Is the type readable.booleanisWriteable(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) write(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull MutableHttpResponse<T> outgoingResponse, @NonNull Argument<T> type, @NonNull MediaType mediaType, T object) Writes an object as aByteBodyHttpResponse.writePiece(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull HttpResponse<?> response, @NonNull Argument<T> type, @NonNull MediaType mediaType, T object) Write a piece of a larger response, e.g.ByteBuffer<?>writeTo(Argument<T> type, MediaType mediaType, T object, MutableHeaders outgoingHeaders, ByteBufferFactory<?, ?> bufferFactory) Writes an object to the given stream.voidwriteTo(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:
customizein interfaceCustomizableJsonHandler
-
readChunked
public Publisher<T> readChunked(Argument<T> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) - Specified by:
readChunkedin interfaceChunkedMessageBodyReader<T>
-
isReadable
Description copied from interface:MessageBodyReaderIs the type readable.- Specified by:
isReadablein 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:MessageBodyReaderReads an object from the given byte buffer.- Specified by:
readin interfaceMessageBodyReader<T>- Parameters:
type- The type being decoded.mediaType- The media type, can benullhttpHeaders- 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:MessageBodyReaderReads an object from the given byte buffer.- Specified by:
readin interfaceMessageBodyReader<T>- Parameters:
type- The type being decoded.mediaType- The media type, can benullhttpHeaders- The HTTP headersinputStream- The input stream- Returns:
- The read object or
null - Throws:
CodecException- If an error occurs decoding
-
isWriteable
Description copied from interface:MessageBodyWriterIs the type writeable.- Specified by:
isWriteablein 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:MessageBodyWriterWrites an object to the given output stream.- Specified by:
writeToin 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:MessageBodyWriterWrites an object to the given stream.- Specified by:
writeToin 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
-
write
public ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<T> outgoingResponse, @NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, @NonNull T object) throws CodecException Description copied from interface:ResponseBodyWriterWrites an object as aByteBodyHttpResponse.- Specified by:
writein interfaceResponseBodyWriter<T>- Parameters:
bodyFactory- The buffer factoryrequest- The requestoutgoingResponse- The responsetype- The response body typemediaType- The media typeobject- The object to write- Returns:
- A
ByteBodyHttpResponsewith the response bytes - Throws:
CodecException- If an error occurs encoding
-
writePiece
public CloseableByteBody writePiece(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull HttpResponse<?> response, @NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, T object) Description copied from interface:ResponseBodyWriterWrite a piece of a larger response, e.g. when writing a Publisher or a part of a multipart response. In this case, response headers cannot be modified.- Specified by:
writePiecein interfaceResponseBodyWriter<T>- Parameters:
bodyFactory- The buffer factoryrequest- The requestresponse- The response this piece is part oftype- The type of this piecemediaType- The media type of this pieceobject- The piece to write- Returns:
- The response bytes
-
createSpecific
Description copied from interface:MessageBodyWriterPrepare aMessageBodyWriterthat will write the given type. This can be used for precomputing some route data.- Specified by:
createSpecificin interfaceMessageBodyWriter<T>- Parameters:
type- The type- Returns:
- The closure
-
isBlocking
public boolean isBlocking()Description copied from interface:MessageBodyWritertrueiff 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 theOutputStreamthat is passed as the write destination may still block.- Specified by:
isBlockingin interfaceMessageBodyWriter<T>- Returns:
- Whether this writer may block
-