Package gda.util
Class JsonMessageConverter
java.lang.Object
gda.util.JsonMessageConverter
Utility class to convert JMS text and bytes messages to/from JSON
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TfromMessage(javax.jms.Message message, Class<T> targetType) Extract the (assumed) JSON body of a JMSMessageand deserialize it to a Java objectjavax.jms.MessageConvert an object to a JSON string inside aTextMessage
-
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 aTextMessage- Parameters:
object- The message body, will be serialized to JSONsession- The JMS session for theTextMessage- Returns:
- a new JMS
Message - Throws:
javax.jms.JMSException- If there is a problem with the sessionJsonMessageConversionException- 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 JMSMessageand deserialize it to a Java object- Type Parameters:
T- The expected type of the body- Parameters:
message- The JMSMessageto decodetargetType- The expected type of the body- Returns:
- The deserialized message body
- Throws:
javax.jms.JMSException- if there a problem extracting the body from the messageJsonMessageConversionException- if there is a problem deserializing the body
-