Class JacksonCodecSupport<T extends tools.jackson.databind.ObjectMapper>
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport<T>
- Type Parameters:
T
- the type ofObjectMapper
- Direct Known Subclasses:
AbstractJacksonDecoder, AbstractJacksonEncoder
public abstract class JacksonCodecSupport<T extends tools.jackson.databind.ObjectMapper>
extends Object
Base class providing support methods for Jackson 3.x encoding and decoding.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JacksonCodecSupport
(tools.jackson.databind.cfg.MapperBuilder<T, ?> builder, MimeType... mimeTypes) Construct a new instance with the providedbuilder
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andMimeType
s.protected
JacksonCodecSupport
(T mapper, MimeType... mimeTypes) Construct a new instance with the providedObjectMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andMimeType
s. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract <A extends Annotation>
@Nullable AgetAnnotation
(MethodParameter parameter, Class<A> annotType) getHints
(ResolvableType resolvableType) protected tools.jackson.databind.JavaType
getJavaType
(Type type, @Nullable Class<?> contextClass) Return theconfigured
default mapper.getMappersForType
(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.Return the supported media type(s) forProblemDetail
.Subclasses should expose this as "decodable" or "encodable" mime types.getMimeTypes
(ResolvableType elementType) protected @Nullable MethodParameter
getParameter
(ResolvableType type) void
Configure theObjectMapper
instances to use for the givenClass
.selectMapper
(ResolvableType targetType, @Nullable MimeType targetMimeType) Select an ObjectMapper to use, either the main ObjectMapper or another if the handling for the given Class has been customized throughregisterMappersForType(Class, Consumer)
.protected boolean
supportsMimeType
(@Nullable MimeType mimeType)
-
Field Details
-
JSON_VIEW_HINT
-
FILTER_PROVIDER_HINT
The key for the hint to specify aFilterProvider
. -
logger
protected final org.apache.commons.logging.Log logger -
mapperRegistrations
-
-
Constructor Details
-
JacksonCodecSupport
-
JacksonCodecSupport
-
-
Method Details
-
getMapper
Return theconfigured
default mapper. -
registerMappersForType
Configure theObjectMapper
instances to use for the givenClass
. This is useful when you want to deviate from thedefault
ObjectMapper or have theObjectMapper
vary byMediaType
.Note: Use of this method effectively turns off use of the default
ObjectMapper
and supportedMimeTypes
for the given class. Therefore it is important for the mappings configured here toinclude
every MediaType that must be supported for the given class.- Parameters:
clazz
- the type of Object to register ObjectMapper instances forregistrar
- a consumer to populate or otherwise update the MediaType-to-ObjectMapper associations for the given Class
-
getMappersForType
Return ObjectMapper registrations for the given class, if any.- Parameters:
clazz
- the class to look up for registrations for- Returns:
- a map with registered MediaType-to-ObjectMapper registrations, or empty if in case of no registrations for the given class.
-
getMapperRegistrations
-
getMimeTypes
-
getMimeTypes
-
getMediaTypesForProblemDetail
Return the supported media type(s) forProblemDetail
. By default, an empty list, unless overridden in subclasses. -
supportsMimeType
-
getJavaType
-
getHints
-
getParameter
-
getAnnotation
protected abstract <A extends Annotation> @Nullable A getAnnotation(MethodParameter parameter, Class<A> annotType) -
selectMapper
Select an ObjectMapper to use, either the main ObjectMapper or another if the handling for the given Class has been customized throughregisterMappersForType(Class, Consumer)
.
-