Class JacksonJsonMessageConverter

java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.messaging.converter.JacksonJsonMessageConverter
All Implemented Interfaces:
MessageConverter, SmartMessageConverter

public class JacksonJsonMessageConverter extends AbstractMessageConverter
A Jackson 3.x based MessageConverter implementation.
Since:
7.0
Author:
Sebastien Deleuze
  • Constructor Details

    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter()
      Construct a new instance with a JsonMapper customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader).
    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter(MimeType... supportedMimeTypes)
      Construct a new instance with a JsonMapper customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader) and the provided MimeTypes.
      Parameters:
      supportedMimeTypes - the supported MIME types
    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper mapper)
      Construct a new instance with the provided JsonMapper.
      See Also:
      • JsonMapper.builder()
    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper.Builder builder)
      Construct a new instance with the provided JsonMapper.Builder customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader).
      See Also:
      • JsonMapper.builder()
    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper mapper, MimeType... supportedMimeTypes)
      Construct a new instance with the provided JsonMapper and the provided MimeTypes.
      See Also:
      • JsonMapper.builder()
    • JacksonJsonMessageConverter

      public JacksonJsonMessageConverter(tools.jackson.databind.json.JsonMapper.Builder builder, MimeType... supportedMimeTypes)
      Construct a new instance with the provided JsonMapper customized with the JacksonModules found by MapperBuilder.findModules(ClassLoader), and the provided MimeTypes.
      See Also:
      • JsonMapper.builder()
  • Method Details

    • getJsonMapper

      protected tools.jackson.databind.json.JsonMapper getJsonMapper()
      Return the underlying JsonMapper for this converter.
    • canConvertFrom

      protected boolean canConvertFrom(Message<?> message, @Nullable Class<?> targetClass)
      Overrides:
      canConvertFrom in class AbstractMessageConverter
    • canConvertTo

      protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers)
      Overrides:
      canConvertTo in class AbstractMessageConverter
    • supports

      protected boolean supports(Class<?> clazz)
      Description copied from class: AbstractMessageConverter
      Whether the given class is supported by this converter.
      Specified by:
      supports in class AbstractMessageConverter
      Parameters:
      clazz - the class to test for support
      Returns:
      true if supported; false otherwise
    • convertFromInternal

      protected @Nullable Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint)
      Description copied from class: AbstractMessageConverter
      Convert the message payload from serialized form to an Object.
      Overrides:
      convertFromInternal in class AbstractMessageConverter
      Parameters:
      message - the input message
      targetClass - the target class for the conversion
      conversionHint - an extra object passed to the MessageConverter, for example, the associated MethodParameter (may be null)
      Returns:
      the result of the conversion, or null if the converter cannot perform the conversion
    • convertToInternal

      protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint)
      Description copied from class: AbstractMessageConverter
      Convert the payload object to serialized form.
      Overrides:
      convertToInternal in class AbstractMessageConverter
      Parameters:
      payload - the Object to convert
      headers - optional headers for the message (may be null)
      conversionHint - an extra object passed to the MessageConverter, for example, the associated MethodParameter (may be null)
      Returns:
      the resulting payload for the message, or null if the converter cannot perform the conversion
    • getSerializationView

      protected @Nullable Class<?> getSerializationView(@Nullable Object conversionHint)
      Determine a Jackson serialization view based on the given conversion hint.
      Parameters:
      conversionHint - the conversion hint Object as passed into the converter for the current conversion attempt
      Returns:
      the serialization view class, or null if none
    • getJsonEncoding

      protected tools.jackson.core.JsonEncoding getJsonEncoding(@Nullable MimeType contentType)
      Determine the JSON encoding to use for the given content type.
      Parameters:
      contentType - the MIME type from the MessageHeaders, if any
      Returns:
      the JSON encoding to use (never null)