类 Jackson2CodecSupport
java.lang.Object
cn.taketoday.http.codec.json.Jackson2CodecSupport
Base class providing support methods for Jackson 2.9 encoding and decoding.
- 从以下版本开始:
- 4.0
- 作者:
- Sebastien Deleuze, Rossen Stoyanchev, Harry Yang
-
字段概要
字段修饰符和类型字段说明(专用程序包) static final StringThe key for the hint to access the actual ResolvableType passed intoHttpMessageReader.read(ResolvableType, ResolvableType, ServerHttpRequest, ServerHttpResponse, Map)(server-side only).private static final List<cn.taketoday.util.MimeType>private ObjectMapperstatic final StringThe key for the hint to specify a "JSON View" for encoding or decoding with the value expected to be aClass.private static final Stringprotected final cn.taketoday.logging.Loggerprivate final List<cn.taketoday.util.MimeType>private Map<Class<?>,Map<cn.taketoday.util.MimeType, ObjectMapper>> -
构造器概要
构造器限定符构造器说明protectedJackson2CodecSupport(ObjectMapper objectMapper, cn.taketoday.util.MimeType... mimeTypes) Constructor with a JacksonObjectMapperto use. -
方法概要
修饰符和类型方法说明protected abstract <A extends Annotation>
AgetAnnotation(cn.taketoday.core.MethodParameter parameter, Class<A> annotType) getHints(cn.taketoday.core.ResolvableType resolvableType) protected JavaTypegetJavaType(Type type, Class<?> contextClass) protected List<cn.taketoday.util.MimeType>Return the supported media type(s) forProblemDetail.protected List<cn.taketoday.util.MimeType>Subclasses should expose this as "decodable" or "encodable" mime types.protected List<cn.taketoday.util.MimeType>getMimeTypes(cn.taketoday.core.ResolvableType elementType) Return theconfigureddefault ObjectMapper.protected Map<Class<?>,Map<cn.taketoday.util.MimeType, ObjectMapper>> Map<cn.taketoday.util.MimeType,ObjectMapper> getObjectMappersForType(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.protected cn.taketoday.core.MethodParametergetParameter(cn.taketoday.core.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.protected booleannotSupportsMimeType(cn.taketoday.util.MimeType mimeType) voidregisterObjectMappersForType(Class<?> clazz, Consumer<Map<cn.taketoday.util.MimeType, ObjectMapper>> registrar) Configure theObjectMapperinstances to use for the givenClass.protected ObjectMapperselectObjectMapper(cn.taketoday.core.ResolvableType targetType, cn.taketoday.util.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.
-
字段详细资料
-
JSON_VIEW_HINT
The key for the hint to specify a "JSON View" for encoding or decoding with the value expected to be aClass.- 另请参阅:
-
ACTUAL_TYPE_HINT
The key for the hint to access the actual ResolvableType passed intoHttpMessageReader.read(ResolvableType, ResolvableType, ServerHttpRequest, ServerHttpResponse, Map)(server-side only). Currently set when the method argument has generics because in case of reactive types, use ofResolvableType.getGeneric()means no MethodParameter source and no knowledge of the containing class. -
JSON_VIEW_HINT_ERROR
- 另请参阅:
-
defaultMimeTypes
-
logger
protected final cn.taketoday.logging.Logger logger -
defaultObjectMapper
-
objectMapperRegistrations
@Nullable private Map<Class<?>,Map<cn.taketoday.util.MimeType, objectMapperRegistrationsObjectMapper>> -
mimeTypes
-
-
构造器详细资料
-
Jackson2CodecSupport
Constructor with a JacksonObjectMapperto use.
-
-
方法详细资料
-
setObjectMapper
Configure the default ObjectMapper instance to use.- 参数:
objectMapper- the ObjectMapper instance
-
getObjectMapper
Return theconfigureddefault ObjectMapper. -
registerObjectMappersForType
public void registerObjectMappersForType(Class<?> clazz, Consumer<Map<cn.taketoday.util.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.- 参数:
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
@Nullable public Map<cn.taketoday.util.MimeType,ObjectMapper> getObjectMappersForType(Class<?> clazz) Return ObjectMapper registrations for the given class, if any.- 参数:
clazz- the class to look up for registrations for- 返回:
- a map with registered MediaType-to-ObjectMapper registrations, or empty if in case of no registrations for the given class.
-
getObjectMapperRegistrations
-
getMimeTypes
Subclasses should expose this as "decodable" or "encodable" mime types. -
getMimeTypes
protected List<cn.taketoday.util.MimeType> getMimeTypes(cn.taketoday.core.ResolvableType elementType) -
notSupportsMimeType
protected boolean notSupportsMimeType(@Nullable cn.taketoday.util.MimeType mimeType) -
getMediaTypesForProblemDetail
Return the supported media type(s) forProblemDetail. By default, an empty list, unless overridden in subclasses. -
logWarningIfNecessary
Determine whether to log the given exception coming from aObjectMapper.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 aJsonMappingException)
-
getJavaType
-
getHints
-
getParameter
@Nullable protected cn.taketoday.core.MethodParameter getParameter(cn.taketoday.core.ResolvableType type) -
getAnnotation
@Nullable protected abstract <A extends Annotation> A getAnnotation(cn.taketoday.core.MethodParameter parameter, Class<A> annotType) -
selectObjectMapper
@Nullable protected ObjectMapper selectObjectMapper(cn.taketoday.core.ResolvableType targetType, @Nullable cn.taketoday.util.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).
-