Top Description Methods
org.springframework.http.codec

public Interface HttpMessageWriter<T>

Known Direct Implementers
org.springframework.http.codec.ResourceHttpMessageWriter, org.springframework.http.codec.ServerSentEventHttpMessageWriter, org.springframework.http.codec.multipart.MultipartHttpMessageWriter, org.springframework.http.codec.multipart.PartEventHttpMessageWriter, org.springframework.http.codec.multipart.PartHttpMessageWriter, org.springframework.http.codec.EncoderHttpMessageWriter, org.springframework.http.codec.FormHttpMessageWriter
Type Parameters
<T>
the type of objects in the input stream
Imports
java.util.Collections, .List, .Map, org.reactivestreams.Publisher, reactor.core.publisher.Mono, org.springframework.core.MethodParameter, .ResolvableType, org.springframework.http.MediaType, .ReactiveHttpOutputMessage, org.springframework.http.server.reactive.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable

Strategy for encoding a stream of objects of type <T> and writing the encoded stream of bytes to an ReactiveHttpOutputMessage.
Authors
Rossen Stoyanchev, Arjen Poutsma, Sebastien Deleuze
Since
5.0

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if writable, false otherwise
canWrite
(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the write (possibly null)
mediaType
)

Whether the given object type is supported by this writer.

public List<MediaType>

Returns:

the general list of supported media types
getWritableMediaTypes
()

Return the list of media types supported by this Writer.

public default List<MediaType>

Returns:

the list of media types supported for the given class
getWritableMediaTypes
(ResolvableType
the type of element to encode
elementType
)

Return the list of media types supported by this Writer for the given type of element.

public Mono<Void>

Returns:

indicates completion or error
write
(Publisher<? extends T>
the objects to write
inputStream
,
ResolvableType
the type of objects in the stream which must have been previously checked via canWrite(ResolvableType, MediaType)
elementType
,
MediaType
the content type for the write (possibly null to indicate that the default content type of the writer must be used)
mediaType
,
ReactiveHttpOutputMessage
the message to write to
message
,
Map<String, Object>
additional information about how to encode and write
hints
)

Write a given stream of object to the output message.

public default Mono<Void>

Returns:

a Mono that indicates completion of writing or error
write
(Publisher<? extends T> inputStream, ResolvableType
the actual return type of the method that returned the value; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().
actualType
,
ResolvableType
the type of Objects in the input stream
elementType
,
MediaType
the content type to use (possibly null indicating the default content type of the writer should be used)
mediaType
,
ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
Map<String, Object> hints)

Server-side only alternative to write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map) with additional context available.

Method Detail

canWriteback to summary
public boolean canWrite(ResolvableType elementType, MediaType mediaType)

Whether the given object type is supported by this writer.

Parameters
elementType:ResolvableType

the type of object to check

mediaType:MediaType

the media type for the write (possibly null)

Returns:boolean

true if writable, false otherwise

getWritableMediaTypesback to summary
public List<MediaType> getWritableMediaTypes()

Return the list of media types supported by this Writer. The list may not apply to every possible target element type and calls to this method should typically be guarded via canWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, use getWritableMediaTypes(ResolvableType) for a more precise list.

Returns:List<MediaType>

the general list of supported media types

getWritableMediaTypesback to summary
public default List<MediaType> getWritableMediaTypes(ResolvableType elementType)

Return the list of media types supported by this Writer for the given type of element. This list may differ from getWritableMediaTypes() if the Writer doesn't support the element type, or if it supports it only for a subset of media types.

Parameters
elementType:ResolvableType

the type of element to encode

Returns:List<MediaType>

the list of media types supported for the given class

Since
5.3.4
writeback to summary
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints)

Write a given stream of object to the output message.

Parameters
inputStream:Publisher<? extends T>

the objects to write

elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canWrite(ResolvableType, MediaType)

mediaType:MediaType

the content type for the write (possibly null to indicate that the default content type of the writer must be used)

message:ReactiveHttpOutputMessage

the message to write to

hints:Map<String, Object>

additional information about how to encode and write

Returns:Mono<Void>

indicates completion or error

writeback to summary
public default 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 write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map) with additional context available.

Parameters
actualType:ResolvableType

the actual return type of the method that returned the value; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().

elementType:ResolvableType

the type of Objects in the input stream

mediaType:MediaType

the content type to use (possibly null indicating the default content type of the writer should be used)

request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

Returns:Mono<Void>

a Mono that indicates completion of writing or error