Top Description Constructors Methods
org.springframework.jms.support.converter

public Class SimpleMessageConverter

extends Object
implements MessageConverter
Class Inheritance
All Implemented Interfaces
org.springframework.jms.support.converter.MessageConverter
Imports
java.io.Serializable, java.util.Enumeration, .HashMap, .Map, jakarta.jms.BytesMessage, .JMSException, .MapMessage, .Message, .ObjectMessage, .Session, .TextMessage, org.springframework.util.ObjectUtils

A simple message converter which is able to handle TextMessages, BytesMessages, MapMessages, and ObjectMessages. Used as default conversion strategy by org.springframework.jms.core.JmsTemplate, for convertAndSend and receiveAndConvert operations.

Converts a String to a jakarta.jms.TextMessage, a byte array to a jakarta.jms.BytesMessage, a Map to a jakarta.jms.MapMessage, and a Serializable object to a jakarta.jms.ObjectMessage (or vice versa).

Authors
Juergen Hoeller, Sam Brannen
Since
1.1
See Also
org.springframework.jms.core.JmsTemplate#convertAndSend, org.springframework.jms.core.JmsTemplate#receiveAndConvert

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected BytesMessage

Returns:

the resulting message
createMessageForByteArray
(byte[]
the byte array to convert
bytes
,
Session
current JMS session
session
)

Create a JMS BytesMessage for the given byte array.

protected MapMessage

Returns:

the resulting message
createMessageForMap
(Map<?, ?>
the Map to convert
map
,
Session
current JMS session
session
)

Create a JMS MapMessage for the given Map.

protected ObjectMessage

Returns:

the resulting message
createMessageForSerializable
(Serializable
the Serializable object to convert
object
,
Session
current JMS session
session
)

Create a JMS ObjectMessage for the given Serializable object.

protected TextMessage

Returns:

the resulting message
createMessageForString
(String
the String to convert
text
,
Session
current JMS session
session
)

Create a JMS TextMessage for the given String.

protected byte[]

Returns:

the resulting byte array
extractByteArrayFromMessage
(BytesMessage
the message to convert
message
)

Extract a byte array from the given BytesMessage.

protected Map<String, Object>

Returns:

the resulting Map
extractMapFromMessage
(MapMessage
the message to convert
message
)

Extract a Map from the given MapMessage.

protected Serializable

Returns:

the resulting Serializable object
extractSerializableFromMessage
(ObjectMessage
the message to convert
message
)

Extract a Serializable object from the given ObjectMessage.

protected String

Returns:

the resulting String
extractStringFromMessage
(TextMessage
the message to convert
message
)

Extract a String from the given TextMessage.

public Object
fromMessage(Message
the message to convert
message
)

Implements org.springframework.jms.support.converter.MessageConverter.fromMessage.

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.

public Message
toMessage(Object
the object to convert
object
,
Session
the Session to use for creating a JMS Message
session
)

Implements org.springframework.jms.support.converter.MessageConverter.toMessage.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SimpleMessageConverterback to summary
public SimpleMessageConverter()

Method Detail

createMessageForByteArrayback to summary
protected BytesMessage createMessageForByteArray(byte[] bytes, Session session) throws JMSException

Create a JMS BytesMessage for the given byte array.

Parameters
bytes:byte[]

the byte array to convert

session:Session

current JMS session

Returns:BytesMessage

the resulting message

Exceptions
JMSException:
if thrown by JMS methods
See Also
jakarta.jms.Session#createBytesMessage
createMessageForMapback to summary
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException

Create a JMS MapMessage for the given Map.

Parameters
map:Map<?, ?>

the Map to convert

session:Session

current JMS session

Returns:MapMessage

the resulting message

Exceptions
JMSException:
if thrown by JMS methods
See Also
jakarta.jms.Session#createMapMessage
createMessageForSerializableback to summary
protected ObjectMessage createMessageForSerializable(Serializable object, Session session) throws JMSException

Create a JMS ObjectMessage for the given Serializable object.

Parameters
object:Serializable

the Serializable object to convert

session:Session

current JMS session

Returns:ObjectMessage

the resulting message

Exceptions
JMSException:
if thrown by JMS methods
See Also
jakarta.jms.Session#createObjectMessage
createMessageForStringback to summary
protected TextMessage createMessageForString(String text, Session session) throws JMSException

Create a JMS TextMessage for the given String.

Parameters
text:String

the String to convert

session:Session

current JMS session

Returns:TextMessage

the resulting message

Exceptions
JMSException:
if thrown by JMS methods
See Also
jakarta.jms.Session#createTextMessage
extractByteArrayFromMessageback to summary
protected byte[] extractByteArrayFromMessage(BytesMessage message) throws JMSException

Extract a byte array from the given BytesMessage.

Parameters
message:BytesMessage

the message to convert

Returns:byte[]

the resulting byte array

Exceptions
JMSException:
if thrown by JMS methods
extractMapFromMessageback to summary
protected Map<String, Object> extractMapFromMessage(MapMessage message) throws JMSException

Extract a Map from the given MapMessage.

Parameters
message:MapMessage

the message to convert

Returns:Map<String, Object>

the resulting Map

Annotations
@SuppressWarnings:unchecked
Exceptions
JMSException:
if thrown by JMS methods
extractSerializableFromMessageback to summary
protected Serializable extractSerializableFromMessage(ObjectMessage message) throws JMSException

Extract a Serializable object from the given ObjectMessage.

Parameters
message:ObjectMessage

the message to convert

Returns:Serializable

the resulting Serializable object

Exceptions
JMSException:
if thrown by JMS methods
extractStringFromMessageback to summary
protected String extractStringFromMessage(TextMessage message) throws JMSException

Extract a String from the given TextMessage.

Parameters
message:TextMessage

the message to convert

Returns:String

the resulting String

Exceptions
JMSException:
if thrown by JMS methods
fromMessageback to summary
public Object fromMessage(Message message) throws JMSException, MessageConversionException

Implements org.springframework.jms.support.converter.MessageConverter.fromMessage.

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.

Parameters
message:Message

Doc from org.springframework.jms.support.converter.MessageConverter.fromMessage.

the message to convert

Returns:Object

Doc from org.springframework.jms.support.converter.MessageConverter.fromMessage.

the converted Java object

Annotations
@Override
Exceptions
JMSException:

Doc from org.springframework.jms.support.converter.MessageConverter.fromMessage.

if thrown by JMS API methods

MessageConversionException:

Doc from org.springframework.jms.support.converter.MessageConverter.fromMessage.

in case of conversion failure

See Also
extractStringFromMessage, extractByteArrayFromMessage, extractMapFromMessage, extractSerializableFromMessage
toMessageback to summary
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException

Implements org.springframework.jms.support.converter.MessageConverter.toMessage.

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.

Parameters
object:Object

Doc from org.springframework.jms.support.converter.MessageConverter.toMessage.

the object to convert

session:Session

Doc from org.springframework.jms.support.converter.MessageConverter.toMessage.

the Session to use for creating a JMS Message

Returns:Message

Doc from org.springframework.jms.support.converter.MessageConverter.toMessage.

the JMS Message

Annotations
@Override
Exceptions
JMSException:

Doc from org.springframework.jms.support.converter.MessageConverter.toMessage.

if thrown by JMS API methods

MessageConversionException:

Doc from org.springframework.jms.support.converter.MessageConverter.toMessage.

in case of conversion failure

See Also
createMessageForString, createMessageForByteArray, createMessageForMap, createMessageForSerializable