Class AbstractJackson2Decoder
java.lang.Object
org.springframework.http.codec.json.Jackson2CodecSupport
org.springframework.http.codec.json.AbstractJackson2Decoder
- All Implemented Interfaces:
Decoder<Object>
,HttpMessageDecoder<Object>
- Direct Known Subclasses:
Jackson2CborDecoder
,Jackson2JsonDecoder
,Jackson2SmileDecoder
public abstract class AbstractJackson2Decoder
extends Jackson2CodecSupport
implements HttpMessageDecoder<Object>
Abstract base class for Jackson 2.x decoding, leveraging non-blocking parsing.
- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev, Arjen Poutsma
- See Also:
-
Field Summary
Fields inherited from class org.springframework.http.codec.json.Jackson2CodecSupport
JSON_VIEW_HINT, logger
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractJackson2Decoder
(ObjectMapper mapper, MimeType... mimeTypes) Constructor with a JacksonObjectMapper
to use. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecode
(ResolvableType elementType, @Nullable MimeType mimeType) Whether the decoder supports the given target element type and the MIME type of the source stream.protected ObjectReader
customizeReader
(ObjectReader reader, ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customizeObjectReader
used for reading values.reactor.core.publisher.Flux<Object>
decode
(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode aDataBuffer
input stream into a Flux ofT
.decode
(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode a data buffer to an Object of type T.reactor.core.publisher.Mono<Object>
decodeToMono
(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode aDataBuffer
input stream into a Mono ofT
.protected <A extends Annotation>
@Nullable AgetAnnotation
(MethodParameter parameter, Class<A> annotType) Return the list of MIME types supported by this Decoder.getDecodableMimeTypes
(ResolvableType targetType) Return the list of MIME types supported by this Decoder for the given type of element.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
Return theconfigured
byte count limit.protected reactor.core.publisher.Flux<DataBuffer>
processInput
(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable 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.Methods inherited from class org.springframework.http.codec.json.Jackson2CodecSupport
getHints, getJavaType, getMediaTypesForProblemDetail, getMimeTypes, getMimeTypes, getObjectMapper, getObjectMapperRegistrations, getObjectMappersForType, getParameter, logWarningIfNecessary, registerObjectMappersForType, selectObjectMapper, setObjectMapper, supportsMimeType
-
Constructor Details
-
AbstractJackson2Decoder
Constructor with a JacksonObjectMapper
to use.
-
-
Method Details
-
setMaxInMemorySize
public void setMaxInMemorySize(int byteCount) Set the max number of bytes that can be buffered by this decoder. This is either the size of the entire input when decoding as a whole, or the size of one top-level JSON object within a JSON stream. When the limit is exceeded,DataBufferLimitException
is raised.By default this is set to 256K.
- Parameters:
byteCount
- the max number of bytes to buffer, or -1 for unlimited- Since:
- 5.1.11
-
getMaxInMemorySize
public int getMaxInMemorySize()Return theconfigured
byte count limit.- Since:
- 5.1.11
-
canDecode
Description copied from interface:Decoder
Whether the decoder supports the given target element type and the MIME type of the source stream. -
decode
public reactor.core.publisher.Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:Decoder
Decode aDataBuffer
input stream into a Flux ofT
.- Specified by:
decode
in interfaceDecoder<Object>
- Parameters:
input
- theDataBuffer
input stream to decodeelementType
- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returnedtrue
.mimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do decode- Returns:
- the output stream with decoded elements
-
processInput
protected reactor.core.publisher.Flux<DataBuffer> processInput(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Process the input publisher into a flux. Default implementation returnsFlux.from(Publisher)
, but subclasses can choose to customize this behavior.- Parameters:
input
- theDataBuffer
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 encode- Returns:
- the processed flux
- Since:
- 5.1.14
-
decodeToMono
public reactor.core.publisher.Mono<Object> decodeToMono(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:Decoder
Decode aDataBuffer
input stream into a Mono ofT
.- Specified by:
decodeToMono
in interfaceDecoder<Object>
- Parameters:
input
- theDataBuffer
input stream to decodeelementType
- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returnedtrue
.mimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do decode- Returns:
- the output stream with the decoded element
-
decode
public Object decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingExceptionDescription copied from interface:Decoder
Decode a data buffer to an Object of type T. This is useful for scenarios, that distinct messages (or events) are decoded and handled individually, in fully aggregated form.- Specified by:
decode
in interfaceDecoder<Object>
- Parameters:
dataBuffer
- theDataBuffer
to decodetargetType
- the expected output typemimeType
- the MIME type associated with the datahints
- additional information about how to do decode- Returns:
- the decoded value, possibly
null
- Throws:
DecodingException
-
customizeReader
protected ObjectReader customizeReader(ObjectReader reader, ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customizeObjectReader
used for reading values.- Parameters:
reader
- the reader instance to customizeelementType
- the target type of element values to read tohints
- a map with serialization hints; the Reactor Context, when available, may be accessed under the keyContextView.class.getName()
- Returns:
- the customized
ObjectReader
to use - Since:
- 6.0
-
getDecodeHints
public Map<String,Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) Description copied from interface:HttpMessageDecoder
Get decoding hints based on the server request or annotations on the target controller method parameter.- Specified by:
getDecodeHints
in interfaceHttpMessageDecoder<Object>
- Parameters:
actualType
- the actual target type to decode to, possibly a reactive wrapper and sourced fromMethodParameter
, i.e. providing access to method parameter annotationselementType
- the element type withinFlux/Mono
that we're trying to decode torequest
- the current requestresponse
- the current response- Returns:
- a Map with hints, possibly empty
-
getDecodableMimeTypes
Description copied from interface:Decoder
Return the list of MIME types supported by this Decoder. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanDecode(elementType, null)
. The list may also exclude MIME types supported only for a specific element type. Alternatively, useDecoder.getDecodableMimeTypes(ResolvableType)
for a more precise list.- Specified by:
getDecodableMimeTypes
in interfaceDecoder<Object>
- Returns:
- the list of supported MIME types
-
getDecodableMimeTypes
Description copied from interface:Decoder
Return the list of MIME types supported by this Decoder for the given type of element. This list may differ fromDecoder.getDecodableMimeTypes()
if the Decoder doesn't support the given element type or if it supports it only for a subset of MIME types.- Specified by:
getDecodableMimeTypes
in interfaceDecoder<Object>
- Parameters:
targetType
- the type of element to check for decoding- Returns:
- the list of MIME types supported for the given target type
-
getAnnotation
protected <A extends Annotation> @Nullable A getAnnotation(MethodParameter parameter, Class<A> annotType) - Specified by:
getAnnotation
in classJackson2CodecSupport
-