Class AbstractJacksonDecoder<T extends tools.jackson.databind.ObjectMapper>
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport<T>
org.springframework.http.codec.AbstractJacksonDecoder<T>
- Type Parameters:
T- the type ofObjectMapper
- All Implemented Interfaces:
org.springframework.core.codec.Decoder<Object>, HttpMessageDecoder<Object>
- Direct Known Subclasses:
JacksonCborDecoder, JacksonJsonDecoder, JacksonSmileDecoder
public abstract class AbstractJacksonDecoder<T extends tools.jackson.databind.ObjectMapper>
extends JacksonCodecSupport<T>
implements HttpMessageDecoder<Object>
Abstract base class for Jackson 3.x decoding, leveraging non-blocking parsing.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
Fields inherited from class JacksonCodecSupport
FILTER_PROVIDER_HINT, JSON_VIEW_HINT, logger, mapperRegistrations -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractJacksonDecoder(tools.jackson.databind.cfg.MapperBuilder<T, ?> builder, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedbuildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes.protectedAbstractJacksonDecoder(T mapper, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedObjectMapperandMimeTypes. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) protected tools.jackson.databind.ObjectReadercustomizeReader(tools.jackson.databind.ObjectReader reader, org.springframework.core.ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customizeObjectReaderused for reading values.reactor.core.publisher.Flux<Object> decode(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) decode(org.springframework.core.io.buffer.DataBuffer dataBuffer, org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) reactor.core.publisher.Mono<Object> decodeToMono(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) protected <A extends Annotation>
@Nullable AgetAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) List<org.springframework.util.MimeType> List<org.springframework.util.MimeType> getDecodableMimeTypes(org.springframework.core.ResolvableType targetType) getDecodeHints(org.springframework.core.ResolvableType actualType, org.springframework.core.ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) Get decoding hints based on the server request or annotations on the target controller method parameter.intReturn theconfiguredbyte count limit.protected reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> processInput(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) Process the input publisher into a flux.voidsetMaxInMemorySize(int byteCount) Set the max number of bytes that can be buffered by this decoder.Methods inherited from class JacksonCodecSupport
getHints, getJavaType, getMapper, getMapperRegistrations, getMappersForType, getMediaTypesForProblemDetail, getMimeTypes, getMimeTypes, getParameter, registerMappersForType, selectMapper, supportsMimeType
-
Constructor Details
-
AbstractJacksonDecoder
protected AbstractJacksonDecoder(tools.jackson.databind.cfg.MapperBuilder<T, ?> builder, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedbuildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes. -
AbstractJacksonDecoder
Construct a new instance with the providedObjectMapperandMimeTypes.
-
-
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,DataBufferLimitExceptionis raised.By default this is set to 256K.
- Parameters:
byteCount- the max number of bytes to buffer, or -1 for unlimited
-
getMaxInMemorySize
public int getMaxInMemorySize()Return theconfiguredbyte count limit. -
canDecode
-
decode
public reactor.core.publisher.Flux<Object> decode(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
decodein interfaceorg.springframework.core.codec.Decoder<T extends tools.jackson.databind.ObjectMapper>
-
processInput
protected reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> processInput(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.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- theDataBufferinput 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
-
decodeToMono
public reactor.core.publisher.Mono<Object> decodeToMono(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
decodeToMonoin interfaceorg.springframework.core.codec.Decoder<T extends tools.jackson.databind.ObjectMapper>
-
decode
public Object decode(org.springframework.core.io.buffer.DataBuffer dataBuffer, org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) throws org.springframework.core.codec.DecodingException- Specified by:
decodein interfaceorg.springframework.core.codec.Decoder<T extends tools.jackson.databind.ObjectMapper>- Throws:
org.springframework.core.codec.DecodingException
-
customizeReader
protected tools.jackson.databind.ObjectReader customizeReader(tools.jackson.databind.ObjectReader reader, org.springframework.core.ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customizeObjectReaderused 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
ObjectReaderto use
-
getDecodeHints
public Map<String,Object> getDecodeHints(org.springframework.core.ResolvableType actualType, org.springframework.core.ResolvableType elementType, ServerHttpRequest request, ServerHttpResponse response) Description copied from interface:HttpMessageDecoderGet decoding hints based on the server request or annotations on the target controller method parameter.- Specified by:
getDecodeHintsin interfaceHttpMessageDecoder<T extends tools.jackson.databind.ObjectMapper>- 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/Monothat we're trying to decode torequest- the current requestresponse- the current response- Returns:
- a Map with hints, possibly empty
-
getDecodableMimeTypes
-
getDecodableMimeTypes
-
getAnnotation
protected <A extends Annotation> @Nullable A getAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) - Specified by:
getAnnotationin classJacksonCodecSupport<T extends tools.jackson.databind.ObjectMapper>
-