Class JacksonCodecsupport<T extends tools.jackson.databind.ObjectMapper>

java.lang.Object
org.springframework.http.codec.JacksonCodecsupport<T>
Type Parameters:
T - the type of ObjectMapper
Direct Known subclasses:
AbstractJacksonDecoder, AbstractJacksonEncoder

public abstract class JacksonCodecsupport<T extends tools.jackson.databind.ObjectMapper> extends Object
Base class providing support methods for Jackson 3.x encoding and decoding.
since:
7.0
Author:
sebastien Deleuze
  • Field Details

    • JsON_VIEW_HINT

      public static final&nbsp;string&nbsp;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.
    • FILTER_PROVIDER_HINT

      public static final&nbsp;string&nbsp;FILTER_PROVIDER_HINT
      The key for the hint to specify a FilterProvider.
    • logger

      protected final&nbsp;org.apache.commons.logging.Log&nbsp;logger
    • mapperRegistrations

      protected&nbsp;@Nullable Map<Class<?>, Map<MimeType, T extends tools.jackson.databind.ObjectMapper>>&nbsp;mapperRegistrations
  • Constructor Details

    • JacksonCodecsupport

      protected&nbsp;JacksonCodecsupport(tools.jackson.databind.cfg.MapperBuilder<T,?>&nbsp;builder, MimeType...&nbsp;mimeTypes)
      Construct a new instance with the provided builder customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader) and MimeTypes.
    • JacksonCodecsupport

      protected&nbsp;JacksonCodecsupport(T&nbsp;mapper, MimeType...&nbsp;mimeTypes)
      Construct a new instance with the provided ObjectMapper customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader) and MimeTypes.
  • Method Details

    • getMapper

      public&nbsp;T&nbsp;getMapper()
      Return the configured default mapper.
    • registerMappersForType

      public&nbsp;void&nbsp;registerMappersForType(Class<?>&nbsp;clazz, Consumer<Map<MimeType,T>>&nbsp;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.

      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
    • getMappersForType

      public&nbsp;@Nullable Map<MimeType,T>&nbsp;getMappersForType(Class<?>&nbsp;clazz)
      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.
    • getMapperRegistrations

      protected&nbsp;Map<Class<?>, Map<MimeType,T>>&nbsp;getMapperRegistrations()
    • getMimeTypes

      protected&nbsp;List<MimeType>&nbsp;getMimeTypes()
      subclasses should expose this as "decodable" or "encodable" mime types.
    • getMimeTypes

      protected&nbsp;List<MimeType>&nbsp;getMimeTypes(ResolvableType&nbsp;elementType)
    • getMediaTypesForProblemDetail

      protected&nbsp;List<MimeType>&nbsp;getMediaTypesForProblemDetail()
      Return the supported media type(s) for ProblemDetail. By default, an empty list, unless overridden in subclasses.
    • supportsMimeType

      protected&nbsp;boolean&nbsp;supportsMimeType(@Nullable MimeType&nbsp;mimeType)
    • getJavaType

      protected&nbsp;tools.jackson.databind.JavaType&nbsp;getJavaType(Type&nbsp;type, @Nullable Class<?>&nbsp;contextClass)
    • getHints

      protected&nbsp;Map<string,Object>&nbsp;getHints(ResolvableType&nbsp;resolvableType)
    • getParameter

      protected&nbsp;@Nullable MethodParameter&nbsp;getParameter(ResolvableType&nbsp;type)
    • getAnnotation

      protected abstract&nbsp;<A extends Annotation> @Nullable A&nbsp;getAnnotation(MethodParameter&nbsp;parameter, Class<A>&nbsp;annotType)
    • selectMapper

      protected&nbsp;@Nullable T&nbsp;selectMapper(ResolvableType&nbsp;targetType, @Nullable MimeType&nbsp;targetMimeType)
      select an ObjectMapper to use, either the main ObjectMapper or another if the handling for the given Class has been customized through registerMappersForType(Class, Consumer).