类 Jackson2CodecSupport

java.lang.Object
cn.taketoday.http.codec.json.Jackson2CodecSupport
直接已知子类:
AbstractJackson2Decoder, AbstractJackson2Encoder

public abstract class Jackson2CodecSupport extends Object
Base class providing support methods for Jackson 2.9 encoding and decoding.
从以下版本开始:
4.0
作者:
Sebastien Deleuze, Rossen Stoyanchev, Harry Yang
  • 字段详细资料

    • JSON_VIEW_HINT

      public static final 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.
      另请参阅:
    • ACTUAL_TYPE_HINT

      static final String ACTUAL_TYPE_HINT
      The key for the hint to access the actual ResolvableType passed into HttpMessageReader.read(ResolvableType, ResolvableType, ServerHttpRequest, ServerHttpResponse, Map) (server-side only). Currently set when the method argument has generics because in case of reactive types, use of ResolvableType.getGeneric() means no MethodParameter source and no knowledge of the containing class.
    • JSON_VIEW_HINT_ERROR

      private static final String JSON_VIEW_HINT_ERROR
      另请参阅:
    • defaultMimeTypes

      private static final List<cn.taketoday.util.MimeType> defaultMimeTypes
    • logger

      protected final cn.taketoday.logging.Logger logger
    • defaultObjectMapper

      private ObjectMapper defaultObjectMapper
    • objectMapperRegistrations

      @Nullable private Map<Class<?>,Map<cn.taketoday.util.MimeType,ObjectMapper>> objectMapperRegistrations
    • mimeTypes

      private final List<cn.taketoday.util.MimeType> mimeTypes
  • 构造器详细资料

    • Jackson2CodecSupport

      protected Jackson2CodecSupport(ObjectMapper objectMapper, cn.taketoday.util.MimeType... mimeTypes)
      Constructor with a Jackson ObjectMapper to use.
  • 方法详细资料

    • setObjectMapper

      public void setObjectMapper(ObjectMapper objectMapper)
      Configure the default ObjectMapper instance to use.
      参数:
      objectMapper - the ObjectMapper instance
    • getObjectMapper

      public ObjectMapper getObjectMapper()
      Return the configured default ObjectMapper.
    • registerObjectMappersForType

      public void registerObjectMappersForType(Class<?> clazz, Consumer<Map<cn.taketoday.util.MimeType,ObjectMapper>> registrar)
      Configure the 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 for
      registrar - 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

      protected Map<Class<?>,Map<cn.taketoday.util.MimeType,ObjectMapper>> getObjectMapperRegistrations()
    • getMimeTypes

      protected List<cn.taketoday.util.MimeType> 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

      protected List<cn.taketoday.util.MimeType> getMediaTypesForProblemDetail()
      Return the supported media type(s) for ProblemDetail. By default, an empty list, unless overridden in subclasses.
    • logWarningIfNecessary

      protected void logWarningIfNecessary(Type type, @Nullable Throwable cause)
      参数:
      type - the class that Jackson tested for (de-)serializability
      cause - the Jackson-thrown exception to evaluate (typically a JsonMappingException)
    • getJavaType

      protected JavaType getJavaType(Type type, @Nullable Class<?> contextClass)
    • getHints

      protected Map<String,Object> getHints(cn.taketoday.core.ResolvableType resolvableType)
    • 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 through registerObjectMappersForType(Class, Consumer).