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> @NonNull ResponseBodyWriter<T>wrap(@NonNull MessageBodyWriter<T> writer) Wrap the given writer, if necessary, to get aResponseBodyWriter.default @NonNull ByteBodyHttpResponse<?>write(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull MutableHttpResponse<T> httpResponse, @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.Methods inherited from interface io.micronaut.http.body.MessageBodyWriter
createSpecific, isBlocking, isWriteable, writeTo, writeTo
-
Method Details
-
write
@NonNull default @NonNull ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<T> httpResponse, @NonNull @NonNull Argument<T> type, @NonNull @NonNull 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
@NonNull @NonNull 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) 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
@NonNull static <T> @NonNull ResponseBodyWriter<T> wrap(@NonNull @NonNull MessageBodyWriter<T> writer) 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
-