Package gda.util

Class JsonMessageConverter

java.lang.Object
gda.util.JsonMessageConverter

public class JsonMessageConverter extends Object
Utility class to convert JMS text and bytes messages to/from JSON
  • Constructor Details

    • JsonMessageConverter

      public JsonMessageConverter()
  • Method Details

    • toMessage

      public javax.jms.Message toMessage(Object object, javax.jms.Session session) throws javax.jms.JMSException, JsonMessageConversionException
      Convert an object to a JSON string inside a TextMessage
      Parameters:
      object - The message body, will be serialized to JSON
      session - The JMS session for the TextMessage
      Returns:
      a new JMS Message
      Throws:
      javax.jms.JMSException - If there is a problem with the session
      JsonMessageConversionException - if there is a problem serializing the body
    • fromMessage

      public <T> T fromMessage(javax.jms.Message message, Class<T> targetType) throws javax.jms.JMSException, JsonMessageConversionException
      Extract the (assumed) JSON body of a JMS Message and deserialize it to a Java object
      Type Parameters:
      T - The expected type of the body
      Parameters:
      message - The JMS Message to decode
      targetType - The expected type of the body
      Returns:
      The deserialized message body
      Throws:
      javax.jms.JMSException - if there a problem extracting the body from the message
      JsonMessageConversionException - if there is a problem deserializing the body