public abstract class Jackson2CodecSupport extends Object
Modifier and Type | Field and Description |
---|---|
static String |
JSON_VIEW_HINT
The key for the hint to specify a "JSON View" for encoding or decoding
with the value expected to be a
Class . |
protected Log |
logger |
Modifier | Constructor and Description |
---|---|
protected |
Jackson2CodecSupport(ObjectMapper objectMapper,
MimeType... mimeTypes)
Constructor with a Jackson
ObjectMapper to use. |
Modifier and Type | Method and Description |
---|---|
protected abstract <A extends Annotation> |
getAnnotation(MethodParameter parameter,
Class<A> annotType) |
protected Map<String,Object> |
getHints(ResolvableType resolvableType) |
protected JavaType |
getJavaType(Type type,
Class<?> contextClass) |
protected List<MimeType> |
getMimeTypes()
Subclasses should expose this as "decodable" or "encodable" mime types.
|
protected List<MimeType> |
getMimeTypes(ResolvableType elementType) |
ObjectMapper |
getObjectMapper()
Return the
configured default ObjectMapper. |
protected Map<Class<?>,Map<MimeType,ObjectMapper>> |
getObjectMapperRegistrations() |
Map<MimeType,ObjectMapper> |
getObjectMappersForType(Class<?> clazz)
Return ObjectMapper registrations for the given class, if any.
|
protected MethodParameter |
getParameter(ResolvableType type) |
protected void |
logWarningIfNecessary(Type type,
Throwable cause)
Determine whether to log the given exception coming from a
ObjectMapper.canDeserialize(com.fasterxml.jackson.databind.JavaType) / ObjectMapper.canSerialize(java.lang.Class<?>) check. |
void |
registerObjectMappersForType(Class<?> clazz,
Consumer<Map<MimeType,ObjectMapper>> registrar)
Configure the
ObjectMapper instances to use for the given
Class . |
protected ObjectMapper |
selectObjectMapper(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 through
registerObjectMappersForType(Class, Consumer) . |
void |
setObjectMapper(ObjectMapper objectMapper)
Configure the default ObjectMapper instance to use.
|
protected boolean |
supportsMimeType(MimeType mimeType) |
public static final String JSON_VIEW_HINT
Class
.protected final Log logger
protected Jackson2CodecSupport(ObjectMapper objectMapper, MimeType... mimeTypes)
ObjectMapper
to use.public void setObjectMapper(ObjectMapper objectMapper)
objectMapper
- the ObjectMapper instancepublic ObjectMapper getObjectMapper()
configured
default ObjectMapper.public void registerObjectMappersForType(Class<?> clazz, Consumer<Map<MimeType,ObjectMapper>> registrar)
ObjectMapper
instances to use for the given
Class
. This is useful when you want to deviate from the
default
ObjectMapper or have the
ObjectMapper
vary by MediaType
.
Note: Use of this method effectively turns off use of
the default ObjectMapper
and supported
MimeTypes
for the given class. Therefore it is
important for the mappings configured here to
include
every MediaType that must
be supported for the given class.
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@Nullable public Map<MimeType,ObjectMapper> getObjectMappersForType(Class<?> clazz)
clazz
- the class to look up for registrations forprotected Map<Class<?>,Map<MimeType,ObjectMapper>> getObjectMapperRegistrations()
protected List<MimeType> getMimeTypes()
protected List<MimeType> getMimeTypes(ResolvableType elementType)
protected void logWarningIfNecessary(Type type, @Nullable Throwable cause)
ObjectMapper.canDeserialize(com.fasterxml.jackson.databind.JavaType)
/ ObjectMapper.canSerialize(java.lang.Class<?>)
check.type
- the class that Jackson tested for (de-)serializabilitycause
- the Jackson-thrown exception to evaluate
(typically a JsonMappingException
)protected Map<String,Object> getHints(ResolvableType resolvableType)
@Nullable protected MethodParameter getParameter(ResolvableType type)
@Nullable protected abstract <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType)
@Nullable protected ObjectMapper selectObjectMapper(ResolvableType targetType, @Nullable MimeType targetMimeType)
registerObjectMappersForType(Class, Consumer)
.