spring-framework / org.springframework.jms.support.converter / MarshallingMessageConverter

MarshallingMessageConverter

open class MarshallingMessageConverter : MessageConverter, InitializingBean

Spring JMS MessageConverter that uses a Marshaller and Unmarshaller. Marshals an object to a BytesMessage, or to a TextMessage if the targetType is set to MessageType#TEXT. Unmarshals from a TextMessage or BytesMessage to an object.

Author
Arjen Poutsma

Author
Juergen Hoeller

Since
3.0

See Also
org.springframework.jms.core.JmsTemplate#convertAndSendorg.springframework.jms.core.JmsTemplate#receiveAndConvert

Constructors

<init>

MarshallingMessageConverter()

Construct a new MarshallingMessageConverter with no Marshaller or Unmarshaller set. The marshaller must be set after construction by invoking #setMarshaller(Marshaller) and #setUnmarshaller(Unmarshaller) .

MarshallingMessageConverter(marshaller: Marshaller)

Construct a new MarshallingMessageConverter with the given Marshaller set.

If the given Marshaller also implements the Unmarshaller interface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.

Note that all Marshaller implementations in Spring also implement the Unmarshaller interface, so that you can safely use this constructor.

MarshallingMessageConverter(marshaller: Marshaller, unmarshaller: Unmarshaller)

Construct a new MarshallingMessageConverter with the given Marshaller and Unmarshaller.

Functions

afterPropertiesSet

open fun afterPropertiesSet(): Unit

fromMessage

open fun fromMessage(message: Message): Any

This implementation unmarshals the given Message into an object.

setMarshaller

open fun setMarshaller(marshaller: Marshaller): Unit

Set the Marshaller to be used by this message converter.

setTargetType

open fun setTargetType(targetType: MessageType): Unit

Specify whether #toMessage(Object, Session) should marshal to a BytesMessage or a TextMessage.

The default is MessageType#BYTES, i.e. this converter marshals to a BytesMessage. Note that the default version of this converter supports MessageType#BYTES and MessageType#TEXT only.

setUnmarshaller

open fun setUnmarshaller(unmarshaller: Unmarshaller): Unit

Set the Unmarshaller to be used by this message converter.

toMessage

open fun toMessage(object: Any, session: Session): Message

This implementation marshals the given object to a javax.jms.TextMessage or javax.jms.BytesMessage. The desired message type can be defined by setting the "marshalTo" property.