Package org.springframework.http.codec
Class DecoderHttpMessageReader<T>
- java.lang.Object
- org.springframework.http.codec.DecoderHttpMessageReader<T>
- Type Parameters:
T
- the type of objects in the decoded output stream
- All Implemented Interfaces:
HttpMessageReader<T>
- Direct Known Subclasses:
ResourceHttpMessageReader
public class DecoderHttpMessageReader<T> extends Object implements HttpMessageReader<T>
HttpMessageReader
that wraps and delegates to aDecoder
.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.- Since:
- 5.0
- Author:
- Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description DecoderHttpMessageReader(Decoder<T> decoder)
Create an instance wrapping the givenDecoder
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRead(ResolvableType elementType, MediaType mediaType)
Whether the given object type is supported by this reader.protected MediaType
getContentType(HttpMessage inputMessage)
Determine the Content-Type of the HTTP message based on the "Content-Type" header or otherwise default toMediaType.APPLICATION_OCTET_STREAM
.Decoder<T>
getDecoder()
Return theDecoder
of this reader.List<MediaType>
getReadableMediaTypes()
Return theMediaType
's that this reader supports.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.reactor.core.publisher.Flux<T>
read(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Server-side only alternative toHttpMessageReader.read(ResolvableType, ReactiveHttpInputMessage, Map)
with additional context available.reactor.core.publisher.Flux<T>
read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Read from the input message and encode to a stream of objects.reactor.core.publisher.Mono<T>
readMono(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Server-side only alternative toHttpMessageReader.readMono(ResolvableType, ReactiveHttpInputMessage, Map)
with additional, context available.reactor.core.publisher.Mono<T>
readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Read from the input message and encode to a single object.
Constructor Detail
DecoderHttpMessageReader
public DecoderHttpMessageReader(Decoder<T> decoder)
Create an instance wrapping the givenDecoder
.
Method Detail
getDecoder
public Decoder<T> getDecoder()
Return theDecoder
of this reader.
getReadableMediaTypes
public List<MediaType> getReadableMediaTypes()
Description copied from interface:HttpMessageReader
Return theMediaType
's that this reader supports.- Specified by:
getReadableMediaTypes
in interfaceHttpMessageReader<T>
canRead
public boolean canRead(ResolvableType elementType, @Nullable MediaType mediaType)
Description copied from interface:HttpMessageReader
Whether the given object type is supported by this reader.- Specified by:
canRead
in interfaceHttpMessageReader<T>
- Parameters:
elementType
- the type of object to checkmediaType
- the media type for the read (possiblynull
)- Returns:
true
if readable,false
otherwise
read
public reactor.core.publisher.Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Read from the input message and encode to a stream of objects.- Specified by:
read
in interfaceHttpMessageReader<T>
- Parameters:
elementType
- the type of objects in the stream which must have been previously checked viaHttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the input- Returns:
- the decoded stream of elements
readMono
public reactor.core.publisher.Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Read from the input message and encode to a single object.- Specified by:
readMono
in interfaceHttpMessageReader<T>
- Parameters:
elementType
- the type of objects in the stream which must have been previously checked viaHttpMessageReader.canRead(ResolvableType, MediaType)
message
- the message to read fromhints
- additional information about how to read and decode the input- Returns:
- the decoded object
getContentType
@Nullable protected MediaType getContentType(HttpMessage inputMessage)
Determine the Content-Type of the HTTP message based on the "Content-Type" header or otherwise default toMediaType.APPLICATION_OCTET_STREAM
.- Parameters:
inputMessage
- the HTTP message- Returns:
- the MediaType, possibly
null
.
read
public reactor.core.publisher.Flux<T> read(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Server-side only alternative toHttpMessageReader.read(ResolvableType, ReactiveHttpInputMessage, Map)
with additional context available.- Specified by:
read
in interfaceHttpMessageReader<T>
- Parameters:
actualType
- the actual type of the target method parameter; for annotated controllers, theMethodParameter
can be accessed viaResolvableType.getSource()
.elementType
- the type of Objects in the output streamrequest
- the current requestresponse
- the current responsehints
- additional information about how to read the body- Returns:
- the decoded stream of elements
readMono
public reactor.core.publisher.Mono<T> readMono(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Description copied from interface:HttpMessageReader
Server-side only alternative toHttpMessageReader.readMono(ResolvableType, ReactiveHttpInputMessage, Map)
with additional, context available.- Specified by:
readMono
in interfaceHttpMessageReader<T>
- Parameters:
actualType
- the actual type of the target method parameter; for annotated controllers, theMethodParameter
can be accessed viaResolvableType.getSource()
.elementType
- the type of Objects in the output streamrequest
- the current requestresponse
- the current responsehints
- additional information about how to read the body- Returns:
- the decoded stream of elements
getReadHints
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 ofHttpMessageDecoder
.