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
ConstructorsModifierConstructorDescriptionprotectedJacksonCodecSupport(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.protectedJacksonCodecSupport(T mapper, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedObjectMappercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract <A extends Annotation>
@Nullable AgetAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) getHints(org.springframework.core.ResolvableType resolvableType) protected tools.jackson.databind.JavaTypegetJavaType(Type type, @Nullable Class<?> contextClass) Return theconfigureddefault mapper.getMappersForType(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.protected List<org.springframework.util.MimeType> Return the supported media type(s) forProblemDetail.protected List<org.springframework.util.MimeType> Subclasses should expose this as "decodable" or "encodable" mime types.protected List<org.springframework.util.MimeType> getMimeTypes(org.springframework.core.ResolvableType elementType) protected @Nullable org.springframework.core.MethodParametergetParameter(org.springframework.core.ResolvableType type) voidregisterMappersForType(Class<?> clazz, Consumer<Map<org.springframework.util.MimeType, T>> registrar) Configure theObjectMapperinstances to use for the givenClass.selectMapper(org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.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 booleansupportsMimeType(@Nullable org.springframework.util.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
protected JacksonCodecSupport(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. -
JacksonCodecSupport
Construct a new instance with the providedObjectMappercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes.
-
-
Method Details
-
getMapper
Return theconfigureddefault mapper. -
registerMappersForType
public void registerMappersForType(Class<?> clazz, Consumer<Map<org.springframework.util.MimeType, T>> registrar) Configure theObjectMapperinstances to use for the givenClass. This is useful when you want to deviate from thedefaultObjectMapper or have theObjectMappervary byMediaType.Note: Use of this method effectively turns off use of the default
ObjectMapperand supportedMimeTypesfor the given class. Therefore it is important for the mappings configured here toincludeevery 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
Subclasses should expose this as "decodable" or "encodable" mime types. -
getMimeTypes
protected List<org.springframework.util.MimeType> getMimeTypes(org.springframework.core.ResolvableType elementType) -
getMediaTypesForProblemDetail
Return the supported media type(s) forProblemDetail. By default, an empty list, unless overridden in subclasses. -
supportsMimeType
-
getJavaType
-
getHints
-
getParameter
protected @Nullable org.springframework.core.MethodParameter getParameter(org.springframework.core.ResolvableType type) -
getAnnotation
protected abstract <A extends Annotation> @Nullable A getAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) -
selectMapper
protected @Nullable T selectMapper(org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.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).
-