Class ContentTypeDelegatingMessageConverter

  • All Implemented Interfaces:
    MessageConverter

    public class ContentTypeDelegatingMessageConverter
    extends java.lang.Object
    implements MessageConverter
    A composite MessageConverter that delegates to an actual MessageConverter based on the contentType header. Supports a default converter when no content type matches. Note: the MessageProperties requires a content type header to select a converter when used for outbound conversion, but the converter will (generally) override it to match the actual conversion.
    Since:
    1.4.2
    Author:
    Eric Rizzo, Gary Russell, Artem Bilan
    • Constructor Detail

      • ContentTypeDelegatingMessageConverter

        public ContentTypeDelegatingMessageConverter()
        Constructs an instance using a default SimpleMessageConverter.
      • ContentTypeDelegatingMessageConverter

        public ContentTypeDelegatingMessageConverter​(MessageConverter defaultConverter)
        Constructs an instance using a the supplied default converter. May be null meaning a strict content-type match is required.
        Parameters:
        defaultConverter - the converter.
    • Method Detail

      • setDelegates

        public void setDelegates​(java.util.Map<java.lang.String,​MessageConverter> delegatesByContentType)
      • getDelegates

        public java.util.Map<java.lang.String,​MessageConverter> getDelegates()
      • addDelegate

        public void addDelegate​(java.lang.String contentType,
                                MessageConverter messageConverter)
        Add a delegate converter for the content type.
        Parameters:
        contentType - the content type to check.
        messageConverter - the MessageConverter for the content type.
        Since:
        1.6
      • removeDelegate

        public MessageConverter removeDelegate​(java.lang.String contentType)
        Remove the delegate for the content type.
        Parameters:
        contentType - the content type key to remove MessageConverter from delegates.
        Returns:
        the remove MessageConverter.
      • toMessage

        public Message toMessage​(java.lang.Object object,
                                 MessageProperties messageProperties)
        Description copied from interface: MessageConverter
        Convert a Java object to a Message.
        Specified by:
        toMessage in interface MessageConverter
        Parameters:
        object - the object to convert
        messageProperties - The message properties.
        Returns:
        the Message
      • getConverterForContentType

        protected MessageConverter getConverterForContentType​(java.lang.String contentType)