Package io.micronaut.http.body
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
- Author:
- Jonas Konrad
-
Constructor Summary
ConstructorsConstructorDescriptionDynamicMessageBodyWriter(MessageBodyHandlerRegistry registry, List<MediaType> mediaTypes) -
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific(Argument<Object> type) Prepare aMessageBodyWriterthat will write the given type.ByteBuffer<?>writeTo(Argument<Object> type, MediaType mediaType, Object object, MutableHeaders outgoingHeaders, ByteBufferFactory<?, ?> bufferFactory) Writes an object to the given stream.voidwriteTo(Argument<Object> type, MediaType mediaType, Object object, MutableHeaders outgoingHeaders, OutputStream outputStream) Writes an object to the given output stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.body.MessageBodyWriter
isBlocking, isWriteable
-
Constructor Details
-
DynamicMessageBodyWriter
-
-
Method Details
-
createSpecific
Description copied from interface:MessageBodyWriterPrepare aMessageBodyWriterthat will write the given type. This can be used for precomputing some route data.- Specified by:
createSpecificin interfaceMessageBodyWriter<Object>- Parameters:
type- The type- Returns:
- The closure
-
find
-
writeTo
public void writeTo(Argument<Object> type, MediaType mediaType, Object object, MutableHeaders outgoingHeaders, OutputStream outputStream) throws CodecException Description copied from interface:MessageBodyWriterWrites an object to the given output stream.- Specified by:
writeToin interfaceMessageBodyWriter<Object>- Parameters:
type- The typemediaType- The media typeobject- The object to writeoutgoingHeaders- The HTTP headersoutputStream- The output stream- Throws:
CodecException- If an error occurs decoding
-
writeTo
public ByteBuffer<?> writeTo(Argument<Object> type, MediaType mediaType, Object object, MutableHeaders outgoingHeaders, ByteBufferFactory<?, ?> bufferFactory) throws CodecExceptionDescription copied from interface:MessageBodyWriterWrites an object to the given stream.- Specified by:
writeToin interfaceMessageBodyWriter<Object>- Parameters:
type- The typemediaType- The media typeobject- The object to writeoutgoingHeaders- The HTTP headersbufferFactory- A byte buffer factory- Returns:
- The encoded byte buffer
- Throws:
CodecException- If an error occurs decoding
-