Interface ResponseBodyWriter<T>

Type Parameters:
T - The body type
All Superinterfaces:
MessageBodyWriter<T>
All Known Implementing Classes:
CharSequenceBodyWriter

@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
  • Method Details

    • write

      @NonNull @NonNull ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<T> httpResponse, @NonNull @NonNull io.micronaut.core.type.Argument<T> type, @NonNull @NonNull MediaType mediaType, T object) throws CodecException
      Writes an object as a ByteBodyHttpResponse.
      Parameters:
      bodyFactory - The buffer factory
      request - The request
      httpResponse - The response
      type - The response body type
      mediaType - The media type
      object - The object to write
      Returns:
      A ByteBodyHttpResponse with 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 io.micronaut.core.type.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 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
      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 a ResponseBodyWriter.
      Type Parameters:
      T - The body type
      Parameters:
      writer - The generic message writer
      Returns:
      The response writer