Class Jackson2CodecSupport
java.lang.Object
org.springframework.http.codec.json.Jackson2CodecSupport
- Direct Known Subclasses:
- AbstractJackson2Decoder,- AbstractJackson2Encoder
Base class providing support methods for Jackson 2.x encoding and decoding.
- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedJackson2CodecSupport(ObjectMapper objectMapper, MimeType... mimeTypes) Constructor with a JacksonObjectMapperto use.
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract <A extends Annotation>
 AgetAnnotation(MethodParameter parameter, Class<A> annotType) getHints(ResolvableType resolvableType) protected JavaTypegetJavaType(Type type, 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 MethodParametergetParameter(ResolvableType type) protected voidlogWarningIfNecessary(Type type, Throwable cause) Determine whether to log the given exception coming from aObjectMapper.canDeserialize(com.fasterxml.jackson.databind.JavaType)/ObjectMapper.canSerialize(java.lang.Class<?>)check.voidregisterObjectMappersForType(Class<?> clazz, Consumer<Map<MimeType, ObjectMapper>> registrar) Configure theObjectMapperinstances to use for the givenClass.protected ObjectMapperselectObjectMapper(ResolvableType targetType, 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).voidsetObjectMapper(ObjectMapper objectMapper) Configure the default ObjectMapper instance to use.protected booleansupportsMimeType(MimeType mimeType) 
- 
Field Details- 
JSON_VIEW_HINTThe key for the hint to specify a "JSON View" for encoding or decoding with the value expected to be aClass.- See Also:
 
- 
logger
 
- 
- 
Constructor Details- 
Jackson2CodecSupportConstructor with a JacksonObjectMapperto use.
 
- 
- 
Method Details- 
setObjectMapperConfigure the default ObjectMapper instance to use.- Parameters:
- objectMapper- the ObjectMapper instance
- Since:
- 5.3.4
 
- 
getObjectMapperReturn theconfigureddefault ObjectMapper.
- 
registerObjectMappersForTypepublic 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 for
- registrar- a consumer to populate or otherwise update the MediaType-to-ObjectMapper associations for the given Class
- Since:
- 5.3.4
 
- 
getObjectMappersForTypeReturn 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.
- Since:
- 5.3.4
 
- 
getObjectMapperRegistrations
- 
getMimeTypesSubclasses should expose this as "decodable" or "encodable" mime types.
- 
getMimeTypes
- 
getMediaTypesForProblemDetailReturn the supported media type(s) forProblemDetail. By default, an empty list, unless overridden in subclasses.- Since:
- 6.0.5
 
- 
supportsMimeType
- 
logWarningIfNecessaryDetermine whether to log the given exception coming from aObjectMapper.canDeserialize(com.fasterxml.jackson.databind.JavaType)/ObjectMapper.canSerialize(java.lang.Class<?>)check.- Parameters:
- type- the class that Jackson tested for (de-)serializability
- cause- the Jackson-thrown exception to evaluate (typically a- JsonMappingException)
- Since:
- 5.3.1
 
- 
getJavaType
- 
getHints
- 
getParameter
- 
getAnnotation@Nullable protected abstract <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) 
- 
selectObjectMapper@Nullable protected 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).- Since:
- 5.3.4
 
 
-