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.9 decoding, leveraging non-blocking parsing.Compatible with Jackson 2.9.7 and higher.
- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev, Arjen Poutsma
- See Also:
- Add support for non-blocking ("async") JSON parsing
Field Summary
Fields inherited from class org.springframework.http.codec.json.Jackson2CodecSupport
JSON_VIEW_HINT, logger
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractJackson2Decoder(ObjectMapper mapper, MimeType... mimeTypes)
Constructor with a JacksonObjectMapper
to use.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canDecode(ResolvableType elementType, MimeType mimeType)
Whether the decoder supports the given target element type and the MIME type of the source stream.reactor.core.publisher.Flux<Object>
decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)
Decode aDataBuffer
input stream into a Flux ofT
.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.Mono<Object>
decodeToMono(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)
Decode aDataBuffer
input stream into a Mono ofT
.protected <A extends Annotation>
AgetAnnotation(MethodParameter parameter, Class<A> annotType)
List<MimeType>
getDecodableMimeTypes()
Return the list of MIME types this decoder supports.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 theconfigured
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.Methods inherited from class org.springframework.http.codec.json.Jackson2CodecSupport
getHints, getJavaType, getMimeTypes, getObjectMapper, getParameter, supportsMimeType
Constructor Detail
AbstractJackson2Decoder
protected AbstractJackson2Decoder(ObjectMapper mapper, MimeType... mimeTypes)
Constructor with a JacksonObjectMapper
to use.
Method Detail
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
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
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(org.reactivestreams.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 encode- Returns:
- the output stream with decoded elements
processInput
protected reactor.core.publisher.Flux<DataBuffer> processInput(org.reactivestreams.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(org.reactivestreams.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 encode- 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 DecodingException
Description 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 encode- Returns:
- the decoded value, possibly
null
- Throws:
DecodingException
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
public List<MimeType> getDecodableMimeTypes()
Description copied from interface:Decoder
Return the list of MIME types this decoder supports.- Specified by:
getDecodableMimeTypes
in interfaceDecoder<Object>
getAnnotation
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType)
- Specified by:
getAnnotation
in classJackson2CodecSupport