Package io.micronaut.http.body
Interface ResponseBodyWriter<T>
- Type Parameters:
T- The body type
- All Superinterfaces:
MessageBodyWriter<T>
- All Known Implementing Classes:
CharSequenceBodyWriter,FileBodyWriter,InputStreamBodyWriter,JsonMessageHandler,NettyByteBufMessageBodyHandler,NettyJsonHandler,StreamFileBodyWriter,SystemFileBodyWriter,WritableBodyWriter
@Indexed(MessageBodyWriter.class)
public interface ResponseBodyWriter<T>
extends MessageBodyWriter<T>
Extension to
MessageBodyWriter that is specific to writing the server response body. This
allows more fine-grained control over the response than the MessageBodyWriter API.- Since:
- 4.7.0
- Author:
- Jonas Konrad
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ResponseBodyWriter<T> wrap(MessageBodyWriter<T> writer) Wrap the given writer, if necessary, to get aResponseBodyWriter.default ByteBodyHttpResponse<?> write(ByteBodyFactory bodyFactory, HttpRequest<?> request, MutableHttpResponse<T> httpResponse, Argument<T> type, MediaType mediaType, T object) Writes an object as aByteBodyHttpResponse.writePiece(ByteBodyFactory bodyFactory, HttpRequest<?> request, HttpResponse<?> response, Argument<T> type, MediaType mediaType, T object) Write a piece of a larger response, e.g.Methods inherited from interface io.micronaut.http.body.MessageBodyWriter
createSpecific, isBlocking, isWriteable, writeTo, writeTo
-
Method Details
-
write
default ByteBodyHttpResponse<?> write(ByteBodyFactory bodyFactory, HttpRequest<?> request, MutableHttpResponse<T> httpResponse, Argument<T> type, MediaType mediaType, T object) throws CodecException Writes an object as aByteBodyHttpResponse.- Parameters:
bodyFactory- The buffer factoryrequest- The requesthttpResponse- 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
CloseableByteBody writePiece(ByteBodyFactory bodyFactory, HttpRequest<?> request, HttpResponse<?> response, Argument<T> type, MediaType mediaType, T object) throws CodecException Write 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.- 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
- Throws:
CodecException- If an error occurs encoding
-
wrap
Wrap the given writer, if necessary, to get aResponseBodyWriter.- Type Parameters:
T- The body type- Parameters:
writer- The generic message writer- Returns:
- The response writer
-