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 Details

    • write

      default @NonNull ByteBodyHttpResponse<?> write(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull MutableHttpResponse<T> httpResponse, @NonNull Argument<T> type, @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 CloseableByteBody writePiece(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull HttpResponse<?> response, @NonNull Argument<T> type, @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

      static <T> @NonNull ResponseBodyWriter<T> wrap(@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