Class DynamicMessageBodyWriter

java.lang.Object
io.micronaut.http.body.DynamicMessageBodyWriter
All Implemented Interfaces:
MessageBodyWriter<Object>

@Internal public final class DynamicMessageBodyWriter extends Object implements MessageBodyWriter<Object>
Placeholder MessageBodyWriter implementation that decides which writer to use based on the dynamic (runtime) type of the body. Used as fallback where the type is not known statically.
Since:
4.0.0
  • Constructor Details

  • Method Details

    • createSpecific

      public MessageBodyWriter<Object> createSpecific(io.micronaut.core.type.Argument<Object> type)
      Description copied from interface: MessageBodyWriter
      Prepare a MessageBodyWriter that will write the given type. This can be used for precomputing some route data.
      Specified by:
      createSpecific in interface MessageBodyWriter<Object>
      Parameters:
      type - The type
      Returns:
      The closure
    • find

      public MessageBodyWriter<Object> find(io.micronaut.core.type.Argument<Object> type, MediaType mediaType, Object object)
    • writeTo

      public void writeTo(io.micronaut.core.type.Argument<Object> type, MediaType mediaType, Object object, io.micronaut.core.type.MutableHeaders outgoingHeaders, OutputStream outputStream) throws CodecException
      Description copied from interface: MessageBodyWriter
      Writes an object to the given output stream.
      Specified by:
      writeTo in interface MessageBodyWriter<Object>
      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

      public io.micronaut.core.io.buffer.ByteBuffer<?> writeTo(io.micronaut.core.type.Argument<Object> type, MediaType mediaType, Object object, io.micronaut.core.type.MutableHeaders outgoingHeaders, io.micronaut.core.io.buffer.ByteBufferFactory<?,?> bufferFactory) throws CodecException
      Description copied from interface: MessageBodyWriter
      Writes an object to the given stream.
      Specified by:
      writeTo in interface MessageBodyWriter<Object>
      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