T
- the type of objects in the input streampublic class EncoderHttpMessageWriter<T> extends Object implements HttpMessageWriter<T>
HttpMessageWriter
that wraps and delegates to an Encoder
.
Also a HttpMessageWriter
that pre-resolves encoding hints
from the extra information available on the server side such as the request
or controller method annotations.
Constructor and Description |
---|
EncoderHttpMessageWriter(Encoder<T> encoder)
Create an instance wrapping the given
Encoder . |
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
Encoder<T> |
getEncoder()
Return the
Encoder of this writer. |
List<MediaType> |
getWritableMediaTypes()
Return the list of media types supported by this Writer.
|
List<MediaType> |
getWritableMediaTypes(ResolvableType elementType)
Return the list of media types supported by this Writer for the given type
of element.
|
protected Map<String,Object> |
getWriteHints(ResolvableType streamType,
ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response)
Get additional hints for encoding for example based on the server request
or annotations from controller method parameters.
|
reactor.core.publisher.Mono<Void> |
write(Publisher<? extends T> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage message,
Map<String,Object> hints)
Write an given stream of object to the output message.
|
reactor.core.publisher.Mono<Void> |
write(Publisher<? extends T> inputStream,
ResolvableType actualType,
ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response,
Map<String,Object> hints)
Server-side only alternative to
HttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available. |
public List<MediaType> getWritableMediaTypes()
HttpMessageWriter
canWrite(elementType, null)
. The list may also exclude media types
supported only for a specific element type. Alternatively, use
HttpMessageWriter.getWritableMediaTypes(ResolvableType)
for a more precise list.getWritableMediaTypes
in interface HttpMessageWriter<T>
public List<MediaType> getWritableMediaTypes(ResolvableType elementType)
HttpMessageWriter
HttpMessageWriter.getWritableMediaTypes()
if the Writer doesn't support the element type, or if it supports it
only for a subset of media types.getWritableMediaTypes
in interface HttpMessageWriter<T>
elementType
- the type of element to encodepublic boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<T>
elementType
- the type of object to checkmediaType
- the media type for the write (possibly null
)true
if writable, false
otherwisepublic reactor.core.publisher.Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<T>
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been
previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write (possibly null
to
indicate that the default content type of the writer must be used)message
- the message to write tohints
- additional information about how to encode and writepublic reactor.core.publisher.Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
HttpMessageWriter
HttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available.write
in interface HttpMessageWriter<T>
actualType
- the actual return type of the method that returned the
value; for annotated controllers, the MethodParameter
can be
accessed via ResolvableType.getSource()
.elementType
- the type of Objects in the input streammediaType
- the content type to use (possibly null
indicating
the default content type of the writer should be used)request
- the current requestresponse
- the current responseMono
that indicates completion of writing or errorprotected Map<String,Object> getWriteHints(ResolvableType streamType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response)
HttpMessageEncoder
.