Class GenericMessageConverter

  • All Implemented Interfaces:
    org.springframework.messaging.converter.MessageConverter, org.springframework.messaging.converter.SmartMessageConverter

    public class GenericMessageConverter
    extends java.lang.Object
    implements org.springframework.messaging.converter.SmartMessageConverter
    A converter to turn the payload of a Message from serialized form to a typed String and vice versa. This class does not support generic class except List,even for list the entries should be non generic.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object fromMessage​(org.springframework.messaging.Message<?> message, java.lang.Class<?> targetClass)
      Convert the payload of a Message from a serialized form to a typed Object of type stored in message it self.
      java.lang.Object fromMessage​(org.springframework.messaging.Message<?> message, java.lang.Class<?> targetClass, java.lang.Object conversionHint)  
      org.springframework.messaging.Message<?> toMessage​(java.lang.Object payload, org.springframework.messaging.MessageHeaders headers)
      Create a Message whose payload is the result of converting the given payload Object to serialized form.
      org.springframework.messaging.Message<?> toMessage​(java.lang.Object payload, org.springframework.messaging.MessageHeaders headers, java.lang.Object conversionHint)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GenericMessageConverter

        public GenericMessageConverter()
      • GenericMessageConverter

        public GenericMessageConverter​(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • Method Detail

      • fromMessage

        public java.lang.Object fromMessage​(org.springframework.messaging.Message<?> message,
                                            java.lang.Class<?> targetClass)
        Convert the payload of a Message from a serialized form to a typed Object of type stored in message it self.

        If the converter cannot perform the conversion it returns null.

        Specified by:
        fromMessage in interface org.springframework.messaging.converter.MessageConverter
        Parameters:
        message - the input message
        targetClass - the target class for the conversion
        Returns:
        the result of the conversion, or null if the converter cannot perform the conversion.
      • toMessage

        public org.springframework.messaging.Message<?> toMessage​(java.lang.Object payload,
                                                                  org.springframework.messaging.MessageHeaders headers)
        Create a Message whose payload is the result of converting the given payload Object to serialized form. It ignores all headers components.

        If the converter cannot perform the conversion, it return null.

        Specified by:
        toMessage in interface org.springframework.messaging.converter.MessageConverter
        Parameters:
        payload - the Object to convert
        headers - optional headers for the message (may be null)
        Returns:
        the new message, or null
      • fromMessage

        public java.lang.Object fromMessage​(org.springframework.messaging.Message<?> message,
                                            java.lang.Class<?> targetClass,
                                            java.lang.Object conversionHint)
        Specified by:
        fromMessage in interface org.springframework.messaging.converter.SmartMessageConverter
      • toMessage

        public org.springframework.messaging.Message<?> toMessage​(java.lang.Object payload,
                                                                  org.springframework.messaging.MessageHeaders headers,
                                                                  java.lang.Object conversionHint)
        Specified by:
        toMessage in interface org.springframework.messaging.converter.SmartMessageConverter