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 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.
    • FILTER_PROVIDER_HINT

      public static final String FILTER_PROVIDER_HINT
      The key for the hint to specify a FilterProvider.
    • logger

      protected final org.apache.commons.logging.Log logger
    • mapperRegistrations

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

    • JacksonCodecSupport

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

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

    • getMapper

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

      public void registerMappersForType(Class<?> clazz, Consumer<Map<MimeType,T>> 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 @Nullable Map<MimeType,T> getMappersForType(Class<?> 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 Map<Class<?>, Map<MimeType,T>> getMapperRegistrations()
    • getMimeTypes

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

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

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

      protected boolean supportsMimeType(@Nullable MimeType mimeType)
    • getJavaType

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

      protected Map<String,Object> getHints(ResolvableType resolvableType)
    • getParameter

      protected @Nullable MethodParameter getParameter(ResolvableType type)
    • getAnnotation

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

      protected @Nullable T selectMapper(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 through registerMappersForType(Class, Consumer).