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&nbsp;boolean&nbsp;canConvertFrom(Message<?>&nbsp;message, @Nullable Class<?>&nbsp;targetClass)
      Overrides:
      canConvertFrom&nbsp;in class&nbsp;AbstractMessageConverter
    • canConvertTo

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

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

      protected&nbsp;@Nullable Object&nbsp;convertFromInternal(Message<?>&nbsp;message, Class<?>&nbsp;targetClass, @Nullable Object&nbsp;conversionHint)
      Description copied from class:&nbsp;AbstractMessageConverter
      Convert the message payload from serialized form to an Object.
      Overrides:
      convertFromInternal&nbsp;in class&nbsp;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&nbsp;@Nullable Object&nbsp;convertToInternal(Object&nbsp;payload, @Nullable MessageHeaders&nbsp;headers, @Nullable Object&nbsp;conversionHint)
      Description copied from class:&nbsp;AbstractMessageConverter
      Convert the payload object to serialized form.
      Overrides:
      convertToInternal&nbsp;in class&nbsp;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&nbsp;@Nullable Class<?>&nbsp;getserializationView(@Nullable Object&nbsp;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&nbsp;tools.jackson.core.JsonEncoding&nbsp;getJsonEncoding(@Nullable MimeType&nbsp;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)