Class SerializerMessageConverter

All Implemented Interfaces:

public class SerializerMessageConverter extends AllowedListDeserializingMessageConverter
Implementation of MessageConverter that can work with Strings or native objects of any kind via the Serializer and Deserializer abstractions in Spring. The AbstractMessageConverter.toMessage(Object, MessageProperties) method simply checks the type of the provided instance while the fromMessage(Message) method relies upon the content-type of the provided Message.

If a DefaultDeserializer is configured (default), the allowed patterns will be applied (if configured); for all other deserializers, the deserializer is responsible for checking classes, if necessary.

Dave Syer, Gary Russell
  • Field Details

  • Constructor Details

    • SerializerMessageConverter

      public SerializerMessageConverter()
  • Method Details

    • setIgnoreContentType

      public void setIgnoreContentType(boolean ignoreContentType)
      Flag to signal that the content type should be ignored and the deserializer used irrespective if it is a text message. Defaults to false, in which case the default encoding is used to convert a text message to a String.
      ignoreContentType - the flag value to set
    • setDefaultCharset

      public void setDefaultCharset(String defaultCharset)
      Specify the default charset to use when converting to or from text-based Message body content. If not specified, the charset will be "UTF-8".
      defaultCharset - The default charset.
    • setSerializer

      public void setSerializer(Serializer<Object> serializer)
      The serializer to use for converting Java objects to message bodies.
      serializer - the serializer to set
    • setDeserializer

      public void setDeserializer(Deserializer<Object> deserializer)
      The deserializer to use for converting from message body to Java object.
      deserializer - the deserializer to set
    • fromMessage

      public Object fromMessage(Message message) throws MessageConversionException
      Converts from a AMQP Message to an Object.
      message - the message to convert
      the converted Java object
      MessageConversionException - in case of conversion failure
    • createMessage

      protected Message createMessage(Object object, MessageProperties messageProperties) throws MessageConversionException
      Creates an AMQP Message from the provided Object.
      Specified by:
      createMessage in class AbstractMessageConverter
      object - the payload.
      messageProperties - the message properties (headers).
      a message.