Interface MessageBodyWriter<T>

Type Parameters:
T - The generic type.
All Superinterfaces:
io.micronaut.core.order.Ordered
All Known Subinterfaces:
MessageBodyHandler<T>
All Known Implementing Classes:
CharSequenceBodyWriter, TextPlainHandler, WritableBodyWriter

@Indexed(MessageBodyWriter.class) public interface MessageBodyWriter<T> extends io.micronaut.core.order.Ordered
An interface that allows writing a message body for the client or the server.

Implementors can define beans that use Produces to restrict the applicable content types.

Since:
4.0.0
See Also:
  • Field Summary

    Fields inherited from interface io.micronaut.core.order.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Method Summary

    Modifier and Type
    Method
    Description
    createSpecific(io.micronaut.core.type.Argument<T> type)
    Prepare a MessageBodyWriter that will write the given type.
    static Charset
    getCharset(io.micronaut.core.type.Headers headers)
    Resolve the charset.
    default boolean
    true iff this closure can do a blocking read on the object it receives.
    default boolean
    isWriteable(io.micronaut.core.type.Argument<T> type, MediaType mediaType)
    Is the type writeable.
    default io.micronaut.core.io.buffer.ByteBuffer<?>
    writeTo(io.micronaut.core.type.Argument<T> type, MediaType mediaType, T object, io.micronaut.core.type.MutableHeaders outgoingHeaders, io.micronaut.core.io.buffer.ByteBufferFactory<?,?> bufferFactory)
    Writes an object to the given stream.
    void
    writeTo(io.micronaut.core.type.Argument<T> type, MediaType mediaType, T object, io.micronaut.core.type.MutableHeaders outgoingHeaders, OutputStream outputStream)
    Writes an object to the given output stream.

    Methods inherited from interface io.micronaut.core.order.Ordered

    getOrder
  • Method Details

    • isWriteable

      default boolean isWriteable(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable MediaType mediaType)
      Is the type writeable.
      Parameters:
      type - The type
      mediaType - The media type, can be null
      Returns:
      True if is writable
    • createSpecific

      default MessageBodyWriter<T> createSpecific(@NonNull io.micronaut.core.type.Argument<T> type)
      Prepare a MessageBodyWriter that will write the given type. This can be used for precomputing some route data.
      Parameters:
      type - The type
      Returns:
      The closure
    • isBlocking

      default boolean isBlocking()
      true iff this closure can do a blocking read on the object it receives. For example, if this closure writes from an InputStream, that operation may be blocking and this method returns true.
      Note that even when this is false, writeTo(Argument, MediaType, Object, MutableHeaders, OutputStream) may still block because the OutputStream that is passed as the write destination may still block.
      Returns:
      Whether this writer may block
    • getCharset

      @NonNull static Charset getCharset(@NonNull io.micronaut.core.type.Headers headers)
      Resolve the charset.
      Parameters:
      headers - The headers
      Returns:
      The charset
    • writeTo

      void writeTo(@NonNull io.micronaut.core.type.Argument<T> type, @NonNull MediaType mediaType, T object, @NonNull io.micronaut.core.type.MutableHeaders outgoingHeaders, @NonNull OutputStream outputStream) throws CodecException
      Writes an object to the given output stream.
      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
    • writeTo

      @NonNull default io.micronaut.core.io.buffer.ByteBuffer<?> writeTo(@NonNull io.micronaut.core.type.Argument<T> type, @NonNull MediaType mediaType, T object, @NonNull io.micronaut.core.type.MutableHeaders outgoingHeaders, @NonNull io.micronaut.core.io.buffer.ByteBufferFactory<?,?> bufferFactory) throws CodecException
      Writes an object to the given stream.
      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