Class GenericMessageConverter

java.lang.Object
com.github.sonus21.rqueue.converter.GenericMessageConverter
All Implemented Interfaces:
org.springframework.messaging.converter.MessageConverter, org.springframework.messaging.converter.SmartMessageConverter

public class GenericMessageConverter extends 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.
  • Constructor Details

    • GenericMessageConverter

      public GenericMessageConverter()
    • GenericMessageConverter

      public GenericMessageConverter(tools.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • toMessage

      public org.springframework.messaging.Message<?> toMessage(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 Object fromMessage(org.springframework.messaging.Message<?> message, Class<?> targetClass, Object conversionHint)
      Specified by:
      fromMessage in interface org.springframework.messaging.converter.SmartMessageConverter
    • toMessage

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

      public Object fromMessage(org.springframework.messaging.Message<?> message, 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.