Top Description Methods
org.springframework.http.codec

public Interface HttpMessageReader<T>

Known Direct Implementers
org.springframework.http.codec.ServerSentEventHttpMessageReader, org.springframework.http.codec.multipart.DefaultPartHttpMessageReader, org.springframework.http.codec.multipart.MultipartHttpMessageReader, org.springframework.http.codec.multipart.PartEventHttpMessageReader, org.springframework.http.codec.DecoderHttpMessageReader, org.springframework.http.codec.FormHttpMessageReader
Type Parameters
<T>
the type of objects in the decoded output stream
Imports
java.util.Collections, .List, .Map, reactor.core.publisher.Flux, .Mono, org.springframework.core.MethodParameter, .ResolvableType, org.springframework.http.MediaType, .ReactiveHttpInputMessage, org.springframework.http.server.reactive.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable

Strategy for reading from a ReactiveHttpInputMessage and decoding the stream of bytes to Objects of type <T>.
Authors
Rossen Stoyanchev, Arjen Poutsma, Sebastien Deleuze
Since
5.0

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if readable, false otherwise
canRead
(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the read (possibly null)
mediaType
)

Whether the given object type is supported by this reader.

public List<MediaType>

Returns:

the general list of supported media types
getReadableMediaTypes
()

Return the list of media types supported by this reader.

public default List<MediaType>

Returns:

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

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

public Flux<T>

Returns:

the decoded stream of elements
read
(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Read from the input message and decode to a stream of objects.

public default Flux<T>

Returns:

the decoded stream of elements
read
(ResolvableType
the actual type of the target method parameter; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().
actualType
,
ResolvableType
the type of Objects in the output stream
elementType
,
ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
Map<String, Object>
additional information about how to read the body
hints
)

Server-side only alternative to read(ResolvableType, ReactiveHttpInputMessage, Map) with additional context available.

public Mono<T>

Returns:

the decoded object
readMono
(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Read from the input message and decode to a single object.

public default Mono<T>

Returns:

the decoded stream of elements
readMono
(ResolvableType
the actual type of the target method parameter; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().
actualType
,
ResolvableType
the type of Objects in the output stream
elementType
,
ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
Map<String, Object>
additional information about how to read the body
hints
)

Server-side only alternative to readMono(ResolvableType, ReactiveHttpInputMessage, Map) with additional, context available.

Method Detail

canReadback to summary
public boolean canRead(ResolvableType elementType, MediaType mediaType)

Whether the given object type is supported by this reader.

Parameters
elementType:ResolvableType

the type of object to check

mediaType:MediaType

the media type for the read (possibly null)

Returns:boolean

true if readable, false otherwise

getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes()

Return the list of media types supported by this reader. 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 getReadableMediaTypes(ResolvableType) for a more precise list.

Returns:List<MediaType>

the general list of supported media types

getReadableMediaTypesback to summary
public default List<MediaType> getReadableMediaTypes(ResolvableType elementType)

Return the list of media types supported by this Reader for the given type of element. This list may differ from getReadableMediaTypes() if the Reader 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 read

Returns:List<MediaType>

the list of media types supported for the given class

Since
5.3.4
readback to summary
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Read from the input message and decode to a stream of objects.

Parameters
elementType:ResolvableType

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

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Flux<T>

the decoded stream of elements

readback to summary
public default Flux<T> read(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints)

Server-side only alternative to read(ResolvableType, ReactiveHttpInputMessage, Map) with additional context available.

Parameters
actualType:ResolvableType

the actual type of the target method parameter; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().

elementType:ResolvableType

the type of Objects in the output stream

request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

hints:Map<String, Object>

additional information about how to read the body

Returns:Flux<T>

the decoded stream of elements

readMonoback to summary
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Read from the input message and decode to a single object.

Parameters
elementType:ResolvableType

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

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Mono<T>

the decoded object

readMonoback to summary
public default Mono<T> readMono(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> hints)

Server-side only alternative to readMono(ResolvableType, ReactiveHttpInputMessage, Map) with additional, context available.

Parameters
actualType:ResolvableType

the actual type of the target method parameter; for annotated controllers, the MethodParameter can be accessed via ResolvableType#getSource().

elementType:ResolvableType

the type of Objects in the output stream

request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

hints:Map<String, Object>

additional information about how to read the body

Returns:Mono<T>

the decoded stream of elements