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 SummaryConstructors
- 
Method SummaryModifier 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 interface- CustomizableJsonHandler
 
- 
readChunkedpublic Publisher<T> readChunked(Argument<T> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) - Specified by:
- readChunkedin interface- ChunkedMessageBodyReader<T>
 
- 
isReadableDescription copied from interface:MessageBodyReaderIs the type readable.- Specified by:
- isReadablein interface- MessageBodyReader<T>
- Parameters:
- type- The type
- mediaType- The media type, can be- null
- Returns:
- True if is readable
 
- 
readpublic 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 interface- MessageBodyReader<T>
- Parameters:
- type- The type being decoded.
- mediaType- The media type, can be- null
- httpHeaders- The HTTP headers
- byteBuffer- The byte buffer
- Returns:
- The read object or null
- Throws:
- CodecException- If an error occurs decoding
 
- 
readpublic 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 interface- MessageBodyReader<T>
- Parameters:
- type- The type being decoded.
- mediaType- The media type, can be- null
- httpHeaders- The HTTP headers
- inputStream- The input stream
- Returns:
- The read object or null
- Throws:
- CodecException- If an error occurs decoding
 
- 
isWriteableDescription copied from interface:MessageBodyWriterIs the type writeable.- Specified by:
- isWriteablein interface- MessageBodyWriter<T>
- Parameters:
- type- The type
- mediaType- The media type, can be- null
- Returns:
- True if is writable
 
- 
writeTopublic 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 interface- MessageBodyWriter<T>
- Parameters:
- type- The type
- mediaType- The media type
- object- The object to write
- outgoingHeaders- The HTTP headers
- outputStream- The output stream
- Throws:
- CodecException- If an error occurs decoding
 
- 
writeTopublic 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 interface- MessageBodyWriter<T>
- Parameters:
- type- The type
- mediaType- The media type
- object- The object to write
- outgoingHeaders- The HTTP headers
- bufferFactory- A byte buffer factory
- Returns:
- The encoded byte buffer
- Throws:
- CodecException- If an error occurs decoding
 
- 
writepublic 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 interface- ResponseBodyWriter<T>
- Parameters:
- bodyFactory- The buffer factory
- request- The request
- outgoingResponse- The response
- type- The response body type
- mediaType- The media type
- object- The object to write
- Returns:
- A ByteBodyHttpResponsewith the response bytes
- Throws:
- CodecException- If an error occurs encoding
 
- 
writePiecepublic 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 interface- ResponseBodyWriter<T>
- Parameters:
- bodyFactory- The buffer factory
- request- The request
- response- The response this piece is part of
- type- The type of this piece
- mediaType- The media type of this piece
- object- The piece to write
- Returns:
- The response bytes
 
- 
createSpecificDescription copied from interface:MessageBodyWriterPrepare aMessageBodyWriterthat will write the given type. This can be used for precomputing some route data.- Specified by:
- createSpecificin interface- MessageBodyWriter<T>
- Parameters:
- type- The type
- Returns:
- The closure
 
- 
isBlockingpublic 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 interface- MessageBodyWriter<T>
- Returns:
- Whether this writer may block
 
 
-