Class StringMessageConverter

java.lang.Object
org.schlunzis.zis.stomp.client.StringMessageConverter
All Implemented Interfaces:
MessageConverter

public class StringMessageConverter extends Object implements MessageConverter

A MessageConverter implementation that returns the message as-is for String types. It is expected that the message is already a string. Otherwise, an IllegalArgumentException is thrown.

This converter should not be used for more complex applications. Use Jackson2MessageConverter, Jackson3MessageConverter or provide your own implementation of MessageConverter instead.

This message converter always uses the content type "text/plain;charset=UTF-8".

Since:
1.0.0
See Also:
  • Constructor Details

    • StringMessageConverter

      public StringMessageConverter()
      Creates a new StringMessageConverter.
      Since:
      1.0.0
  • Method Details

    • convertToType

      public <T> T convertToType(String messageStr, Class<T> targetType)
      Description copied from interface: MessageConverter
      Converts the given message string to the specified target type.
      Specified by:
      convertToType in interface MessageConverter
      Type Parameters:
      T - the target type
      Parameters:
      messageStr - the message in String format
      targetType - the desired target type class
      Returns:
      the converted message object of the specified target type
    • convertToString

      public String convertToString(Object object)
      Description copied from interface: MessageConverter

      Converts the given object to its String representation.

      The string must be UTF-8 encoded.

      Specified by:
      convertToString in interface MessageConverter
      Parameters:
      object - the object to convert
      Returns:
      the String representation of the object
    • contentType

      public String contentType()
      Description copied from interface: MessageConverter

      Returns the content type associated with this message converter. This content type is used in STOMP message headers to indicate the format of the message body.

      This is typically a MIME type, such as text/plain;charset=UTF-8 or application/json;charset=UTF-8.

      Specified by:
      contentType in interface MessageConverter
      Returns:
      the content type as a String