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 StringThe key for the hint to specify aFilterProvider.static final StringThe 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
ConstructorsModifierConstructorDescriptionprotectedJacksonCodecSupport(MapperBuilder<?, ?> builder, MimeType... mimeTypes) Construct a new instance with the providedbuildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes.protectedJacksonCodecSupport(ObjectMapper objectMapper, 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(MethodParameter parameter, Class<A> annotType) getHints(ResolvableType resolvableType) protected JavaTypegetJavaType(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 theconfigureddefault ObjectMapper.protected Map<Class<?>, Map<MimeType, ObjectMapper>> getObjectMappersForType(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.protected @Nullable MethodParametergetParameter(ResolvableType type) voidregisterObjectMappersForType(Class<?> clazz, Consumer<Map<MimeType, ObjectMapper>> registrar) Configure theObjectMapperinstances to use for the givenClass.protected @Nullable ObjectMapperselectObjectMapper(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 booleansupportsMimeType(@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 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
-
getObjectMapper
Return theconfigureddefault ObjectMapper. -
registerObjectMappersForType
public void registerObjectMappersForType(Class<?> clazz, Consumer<Map<MimeType, ObjectMapper>> 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
-
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).
-