Class Jackson2MessageConverter

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

public class Jackson2MessageConverter extends Object implements MessageConverter

A MessageConverter implementation that uses Jackson 2 to convert messages between JSON string representation and target object types.

The content type used by this converter is application/json;charset=UTF-8.

Since:
1.0.0
See Also:
  • Constructor Details

    • Jackson2MessageConverter

      public Jackson2MessageConverter()
      Creates a new MessageConverter using a default Jackson 2 ObjectMapper.
      Since:
      1.0.0
    • Jackson2MessageConverter

      public Jackson2MessageConverter(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Creates a new MessageConverter using the provided Jackson 2 ObjectMapper.
      Parameters:
      mapper - the ObjectMapper to use for JSON serialization and deserialization
      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