org.springframework.messaging.converter

## Interface SmartMessageConverter

- All Superinterfaces:
    MessageConverter
  All Known Implementing Classes:
    AbstractJsonMessageConverter, AbstractMessageConverter, ByteArrayMessageConverter, CompositeMessageConverter, GsonMessageConverter, JsonbMessageConverter, KotlinSerializationJsonMessageConverter, MappingJackson2MessageConverter, MarshallingMessageConverter, ProtobufJsonFormatMessageConverter, ProtobufMessageConverter, StringMessageConverter

      public interface SmartMessageConverter
      extends MessageConverter

  An extended `MessageConverter` SPI with conversion hint support.

  In case of a conversion hint being provided, the framework will call these extended methods if a converter implements this interface, instead of calling the regular `fromMessage` / `toMessage` variants.

  Since:
    4.2.1
  Author:
    Juergen Hoeller

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `fromMessage(Message<?> message, Class<?> targetClass, Object conversionHint)` A variant of `MessageConverter.fromMessage(Message, Class)` which takes an extra conversion context as an argument, allowing to take e.g.
    `Message<?>` | `toMessage(Object payload, MessageHeaders headers, Object conversionHint)` A variant of `MessageConverter.toMessage(Object, MessageHeaders)` which takes an extra conversion context as an argument, allowing to take e.g.

    - ### Methods inherited from interface org.springframework.messaging.converter.MessageConverter

      `fromMessage, toMessage`

- - ### Method Detail

    - #### fromMessage

          @Nullable
          Object fromMessage(Message<?> message,
                                       Class<?> targetClass,
                                       @Nullable
                                       Object conversionHint)

      A variant of `MessageConverter.fromMessage(Message, Class)` which takes an extra conversion context as an argument, allowing to take e.g. annotations on a payload parameter into account.
      Parameters:
        `message` - the input message
        `targetClass` - the target class for the conversion
        `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
      Returns:
        the result of the conversion, or `null` if the converter cannot perform the conversion
      See Also:
        `MessageConverter.fromMessage(Message, Class)`

    - #### toMessage

          @Nullable
          Message<?> toMessage(Object payload,
                                         @Nullable
                                         MessageHeaders headers,
                                         @Nullable
                                         Object conversionHint)

      A variant of `MessageConverter.toMessage(Object, MessageHeaders)` which takes an extra conversion context as an argument, allowing to take e.g. annotations on a return type into account.
      Parameters:
        `payload` - the Object to convert
        `headers` - optional headers for the message (may be `null`)
        `conversionHint` - an extra object passed to the `MessageConverter`, e.g. the associated `MethodParameter` (may be `null`}
      Returns:
        the new message, or `null` if the converter does not support the Object type or the target media type
      See Also:
        `MessageConverter.toMessage(Object, MessageHeaders)`