Class JacksonCodecSupport
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport
- Direct Known Subclasses:
AbstractJacksonDecoder
,AbstractJacksonEncoder
Base class providing support methods for Jackson 2.x encoding and decoding.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The key for the hint to specify aFilterProvider
.static final String
The key for the hint to specify a "JSON View" for encoding or decoding with the value expected to be aClass
.protected final org.apache.commons.logging.Log
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JacksonCodecSupport
(MapperBuilder<?, ?> builder, MimeType... mimeTypes) Construct a new instance with the providedbuilder
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andMimeType
s.protected
JacksonCodecSupport
(ObjectMapper objectMapper, 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 JavaType
getJavaType
(Type type, @Nullable Class<?> contextClass) Return the supported media type(s) forProblemDetail
.Subclasses should expose this as "decodable" or "encodable" mime types.getMimeTypes
(ResolvableType elementType) Return theconfigured
default ObjectMapper.protected Map
<Class<?>, Map<MimeType, ObjectMapper>> getObjectMappersForType
(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.protected @Nullable MethodParameter
getParameter
(ResolvableType type) void
registerObjectMappersForType
(Class<?> clazz, Consumer<Map<MimeType, ObjectMapper>> registrar) Configure theObjectMapper
instances to use for the givenClass
.protected @Nullable ObjectMapper
selectObjectMapper
(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 throughregisterObjectMappersForType(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 -
objectMapperRegistrations
-
-
Constructor Details
-
JacksonCodecSupport
Construct a new instance with the providedbuilder
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andMimeType
s. -
JacksonCodecSupport
Construct a new instance with the providedObjectMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andMimeType
s.
-
-
Method Details
-
getObjectMapper
Return theconfigured
default ObjectMapper. -
registerObjectMappersForType
public void registerObjectMappersForType(Class<?> clazz, Consumer<Map<MimeType, ObjectMapper>> registrar) 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
-
getObjectMappersForType
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.
-
getObjectMapperRegistrations
-
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) -
selectObjectMapper
protected @Nullable ObjectMapper selectObjectMapper(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 throughregisterObjectMappersForType(Class, Consumer)
.
-