public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport implements HttpMessageDecoder<Object>
Compatible with Jackson 2.9.7 and higher.
JSON_VIEW_HINT, logger
Modifier | Constructor and Description |
---|---|
protected |
AbstractJackson2Decoder(ObjectMapper mapper,
MimeType... mimeTypes)
Constructor with a Jackson
ObjectMapper to use. |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecode(ResolvableType elementType,
MimeType mimeType)
Whether the decoder supports the given target element type and the MIME
type of the source stream.
|
Object |
decode(DataBuffer dataBuffer,
ResolvableType targetType,
MimeType mimeType,
Map<String,Object> hints)
Decode a data buffer to an Object of type T.
|
reactor.core.publisher.Flux<Object> |
decode(org.reactivestreams.Publisher<DataBuffer> input,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Decode a
DataBuffer input stream into a Flux of T . |
reactor.core.publisher.Mono<Object> |
decodeToMono(org.reactivestreams.Publisher<DataBuffer> input,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Decode a
DataBuffer input stream into a Mono of T . |
protected <A extends Annotation> |
getAnnotation(MethodParameter parameter,
Class<A> annotType) |
List<MimeType> |
getDecodableMimeTypes()
Return the list of MIME types supported by this Decoder.
|
List<MimeType> |
getDecodableMimeTypes(ResolvableType targetType)
Return the list of MIME types supported by this Decoder for the given type
of element.
|
Map<String,Object> |
getDecodeHints(ResolvableType actualType,
ResolvableType elementType,
ServerHttpRequest request,
ServerHttpResponse response)
Get decoding hints based on the server request or annotations on the
target controller method parameter.
|
int |
getMaxInMemorySize()
Return the
configured byte count limit. |
protected reactor.core.publisher.Flux<DataBuffer> |
processInput(org.reactivestreams.Publisher<DataBuffer> input,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Process the input publisher into a flux.
|
void |
setMaxInMemorySize(int byteCount)
Set the max number of bytes that can be buffered by this decoder.
|
getHints, getJavaType, getMimeTypes, getMimeTypes, getObjectMapper, getObjectMapperRegistrations, getObjectMappersForType, getParameter, logWarningIfNecessary, registerObjectMappersForType, selectObjectMapper, setObjectMapper, supportsMimeType
protected AbstractJackson2Decoder(ObjectMapper mapper, MimeType... mimeTypes)
ObjectMapper
to use.public void setMaxInMemorySize(int byteCount)
DataBufferLimitException
is raised.
By default this is set to 256K.
byteCount
- the max number of bytes to buffer, or -1 for unlimitedpublic int getMaxInMemorySize()
configured
byte count limit.public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
Decoder
public reactor.core.publisher.Flux<Object> decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
Decoder
DataBuffer
input stream into a Flux of T
.decode
in interface Decoder<Object>
input
- the DataBuffer
input stream to decodeelementType
- the expected type of elements in the output stream;
this type must have been previously passed to the Decoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returned true
.mimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do decodeprotected reactor.core.publisher.Flux<DataBuffer> processInput(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
Flux.from(Publisher)
, but subclasses can choose to customize
this behavior.input
- the DataBuffer
input stream to processelementType
- the expected type of elements in the output streammimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do encodepublic reactor.core.publisher.Mono<Object> decodeToMono(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
Decoder
DataBuffer
input stream into a Mono of T
.decodeToMono
in interface Decoder<Object>
input
- the DataBuffer
input stream to decodeelementType
- the expected type of elements in the output stream;
this type must have been previously passed to the Decoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returned true
.mimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do decodepublic Object decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints) throws DecodingException
Decoder
decode
in interface Decoder<Object>
dataBuffer
- the DataBuffer
to decodetargetType
- the expected output typemimeType
- the MIME type associated with the datahints
- additional information about how to do decodenull
DecodingException
public Map<String,Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response)
HttpMessageDecoder
getDecodeHints
in interface HttpMessageDecoder<Object>
actualType
- the actual target type to decode to, possibly a reactive
wrapper and sourced from MethodParameter
,
i.e. providing access to method parameter annotationselementType
- the element type within Flux/Mono
that we're
trying to decode torequest
- the current requestresponse
- the current responsepublic List<MimeType> getDecodableMimeTypes()
Decoder
canDecode(elementType, null)
. The list may also exclude MIME types
supported only for a specific element type. Alternatively, use
Decoder.getDecodableMimeTypes(ResolvableType)
for a more precise list.getDecodableMimeTypes
in interface Decoder<Object>
public List<MimeType> getDecodableMimeTypes(ResolvableType targetType)
Decoder
Decoder.getDecodableMimeTypes()
if the Decoder doesn't support the given element type or if it supports
it only for a subset of MIME types.getDecodableMimeTypes
in interface Decoder<Object>
targetType
- the type of element to check for decodingprotected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType)
getAnnotation
in class Jackson2CodecSupport