Top Description Fields Constructors Methods
org.springframework.http.codec

public Class DecoderHttpMessageReader<T>

extends Object
implements HttpMessageReader<T>
Class Inheritance
All Implemented Interfaces
org.springframework.http.codec.HttpMessageReader
Known Direct Subclasses
org.springframework.http.codec.ResourceHttpMessageReader
Type Parameters
<T>
the type of objects in the decoded output stream
Imports
java.util.List, .Map, org.apache.commons.logging.Log, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.AbstractDecoder, .Decoder, .Hints, org.springframework.http.HttpLogging, .HttpMessage, .MediaType, .ReactiveHttpInputMessage, org.springframework.http.server.reactive.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable, org.springframework.util.Assert

HttpMessageReader that wraps and delegates to a Decoder.

Also a HttpMessageReader that pre-resolves decoding hints from the extra information available on the server side such as the request or controller method parameter annotations.

Authors
Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private final Decoder<T>
private final List<MediaType>

Constructor Summary

AccessConstructor and Description
public
DecoderHttpMessageReader(Decoder<T> decoder)

Create an instance wrapping the given Decoder.

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the read (possibly null)
mediaType
)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.
protected MediaType

Returns:

the MediaType, possibly null.
getContentType
(HttpMessage
the HTTP message
inputMessage
)

Determine the Content-Type of the HTTP message based on the "Content-Type" header or otherwise default to MediaType#APPLICATION_OCTET_STREAM.

public Decoder<T>
getDecoder()

Return the Decoder of this reader.

public List<MediaType>
getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader.
public List<MediaType>
getReadableMediaTypes(ResolvableType
the type of element to read
elementType
)

Overrides default org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this Reader for the given type of element.
protected Map<String, Object>
getReadHints(ResolvableType elementType, ReactiveHttpInputMessage message)

Get additional hints for decoding based on the input HTTP message.

protected Map<String, Object>
getReadHints(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response)

Get additional hints for decoding for example based on the server request or annotations from controller method parameters.

private static void
initLogger(Decoder<?> decoder)

public Flux<T>
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
)

Implements org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.
public Flux<T>
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
)

Overrides default org.springframework.http.codec.HttpMessageReader.read.

Server-side only alternative to read(ResolvableType, ReactiveHttpInputMessage, Map) with additional context available.
public Mono<T>
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
)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.
public Mono<T>
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
)

Overrides default org.springframework.http.codec.HttpMessageReader.readMono.

Server-side only alternative to readMono(ResolvableType, ReactiveHttpInputMessage, Map) with additional, context available.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decoderback to summary
private final Decoder<T> decoder
mediaTypesback to summary
private final List<MediaType> mediaTypes

Constructor Detail

DecoderHttpMessageReaderback to summary
public DecoderHttpMessageReader(Decoder<T> decoder)

Create an instance wrapping the given Decoder.

Method Detail

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

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Doc from org.springframework.http.codec.HttpMessageReader.canRead.

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

Annotations
@Override
getContentTypeback to summary
protected MediaType getContentType(HttpMessage inputMessage)

Determine the Content-Type of the HTTP message based on the "Content-Type" header or otherwise default to MediaType#APPLICATION_OCTET_STREAM.

Parameters
inputMessage:HttpMessage

the HTTP message

Returns:MediaType

the MediaType, possibly null.

Annotations
@Nullable
getDecoderback to summary
public Decoder<T> getDecoder()

Return the Decoder of this reader.

getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Doc from org.springframework.http.codec.HttpMessageReader.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

Annotations
@Override
getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes(ResolvableType elementType)

Overrides default org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Doc from org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

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

Annotations
@Override
getReadHintsback to summary
protected Map<String, Object> getReadHints(ResolvableType elementType, ReactiveHttpInputMessage message)

Get additional hints for decoding based on the input HTTP message.

Since
5.3
getReadHintsback to summary
protected Map<String, Object> getReadHints(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response)

Get additional hints for decoding for example based on the server request or annotations from controller method parameters. By default, delegate to the decoder if it is an instance of HttpMessageDecoder.

initLoggerback to summary
private static void initLogger(Decoder<?> decoder)
readback to summary
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.read.

Doc from org.springframework.http.codec.HttpMessageReader.read.

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

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

Overrides default org.springframework.http.codec.HttpMessageReader.read.

Doc from org.springframework.http.codec.HttpMessageReader.read.

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

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

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Doc from org.springframework.http.codec.HttpMessageReader.readMono.

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

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

Overrides default org.springframework.http.codec.HttpMessageReader.readMono.

Doc from org.springframework.http.codec.HttpMessageReader.readMono.

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

Annotations
@Override