Class SimpleMessageConverter
java.lang.Object
org.springframework.jms.support.converter.SimpleMessageConverter
- All Implemented Interfaces:
- MessageConverter
A simple message converter which is able to handle TextMessages, BytesMessages,
MapMessages, and ObjectMessages. Used as default conversion strategy
by 
JmsTemplate, for
convertAndSend and receiveAndConvert operations.
Converts a String to a TextMessage, a byte array to a
BytesMessage, a Map to a MapMessage, and
a Serializable object to a ObjectMessage (or vice versa).
- Since:
- 1.1
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected jakarta.jms.BytesMessagecreateMessageForByteArray(byte[] bytes, jakarta.jms.Session session) Create a JMS BytesMessage for the given byte array.protected jakarta.jms.MapMessagecreateMessageForMap(Map<?, ?> map, jakarta.jms.Session session) Create a JMS MapMessage for the given Map.protected jakarta.jms.ObjectMessagecreateMessageForSerializable(Serializable object, jakarta.jms.Session session) Create a JMS ObjectMessage for the given Serializable object.protected jakarta.jms.TextMessagecreateMessageForString(String text, jakarta.jms.Session session) Create a JMS TextMessage for the given String.protected byte[]extractByteArrayFromMessage(jakarta.jms.BytesMessage message) Extract a byte array from the givenBytesMessage.extractMapFromMessage(jakarta.jms.MapMessage message) Extract a Map from the givenMapMessage.protected SerializableextractSerializableFromMessage(jakarta.jms.ObjectMessage message) Extract a Serializable object from the givenObjectMessage.protected StringextractStringFromMessage(jakarta.jms.TextMessage message) Extract a String from the given TextMessage.fromMessage(jakarta.jms.Message message) This implementation converts a TextMessage back to a String, a ByteMessage back to a byte array, a MapMessage back to a Map, and an ObjectMessage back to a Serializable object.jakarta.jms.MessageThis implementation creates a TextMessage for a String, a BytesMessage for a byte array, a MapMessage for a Map, and an ObjectMessage for a Serializable object.
- 
Constructor Details- 
SimpleMessageConverterpublic SimpleMessageConverter()
 
- 
- 
Method Details- 
toMessagepublic jakarta.jms.Message toMessage(Object object, jakarta.jms.Session session) throws jakarta.jms.JMSException, MessageConversionException This implementation creates a TextMessage for a String, a BytesMessage for a byte array, a MapMessage for a Map, and an ObjectMessage for a Serializable object.- Specified by:
- toMessagein interface- MessageConverter
- Parameters:
- object- the object to convert
- session- the Session to use for creating a JMS Message
- Returns:
- the JMS Message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS API methods
- MessageConversionException- in case of conversion failure
- See Also:
 
- 
fromMessagepublic Object fromMessage(jakarta.jms.Message message) throws jakarta.jms.JMSException, MessageConversionException This implementation converts a TextMessage back to a String, a ByteMessage back to a byte array, a MapMessage back to a Map, and an ObjectMessage back to a Serializable object. Returns the plain Message object in case of an unknown message type.- Specified by:
- fromMessagein interface- MessageConverter
- Parameters:
- message- the message to convert
- Returns:
- the converted Java object
- Throws:
- jakarta.jms.JMSException- if thrown by JMS API methods
- MessageConversionException- in case of conversion failure
- See Also:
 
- 
createMessageForStringprotected jakarta.jms.TextMessage createMessageForString(String text, jakarta.jms.Session session) throws jakarta.jms.JMSException Create a JMS TextMessage for the given String.- Parameters:
- text- the String to convert
- session- current JMS session
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- See Also:
 
- 
createMessageForByteArrayprotected jakarta.jms.BytesMessage createMessageForByteArray(byte[] bytes, jakarta.jms.Session session) throws jakarta.jms.JMSException Create a JMS BytesMessage for the given byte array.- Parameters:
- bytes- the byte array to convert
- session- current JMS session
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- See Also:
 
- 
createMessageForMapprotected jakarta.jms.MapMessage createMessageForMap(Map<?, ?> map, jakarta.jms.Session session) throws jakarta.jms.JMSExceptionCreate a JMS MapMessage for the given Map.- Parameters:
- map- the Map to convert
- session- current JMS session
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- See Also:
 
- 
createMessageForSerializableprotected jakarta.jms.ObjectMessage createMessageForSerializable(Serializable object, jakarta.jms.Session session) throws jakarta.jms.JMSException Create a JMS ObjectMessage for the given Serializable object.- Parameters:
- object- the Serializable object to convert
- session- current JMS session
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- See Also:
 
- 
extractStringFromMessageprotected String extractStringFromMessage(jakarta.jms.TextMessage message) throws jakarta.jms.JMSException Extract a String from the given TextMessage.- Parameters:
- message- the message to convert
- Returns:
- the resulting String
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
 
- 
extractByteArrayFromMessageprotected byte[] extractByteArrayFromMessage(jakarta.jms.BytesMessage message) throws jakarta.jms.JMSException Extract a byte array from the givenBytesMessage.- Parameters:
- message- the message to convert
- Returns:
- the resulting byte array
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
 
- 
extractMapFromMessage
- 
extractSerializableFromMessageprotected Serializable extractSerializableFromMessage(jakarta.jms.ObjectMessage message) throws jakarta.jms.JMSException Extract a Serializable object from the givenObjectMessage.- Parameters:
- message- the message to convert
- Returns:
- the resulting Serializable object
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
 
 
-