Class MarshallingMessageConverter
- All Implemented Interfaces:
- InitializingBean, MessageConverter
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.- Since:
- 3.0
- Author:
- Arjen Poutsma, Juergen Hoeller
- 
Constructor SummaryConstructorsConstructorDescriptionMarshallingMessageConverter(Marshaller marshaller) Construct a newMarshallingMessageConverterwith the givenMarshallerset.MarshallingMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) Construct a newMarshallingMessageConverterwith the given Marshaller and Unmarshaller.
- 
Method SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.fromMessage(jakarta.jms.Message message) This implementation unmarshals the givenMessageinto an object.protected jakarta.jms.BytesMessagemarshalToBytesMessage(Object object, jakarta.jms.Session session, Marshaller marshaller) Marshal the given object to aBytesMessage.protected jakarta.jms.MessagemarshalToMessage(Object object, jakarta.jms.Session session, Marshaller marshaller, MessageType targetType) Template method that allows for custom message marshalling.protected jakarta.jms.TextMessagemarshalToTextMessage(Object object, jakarta.jms.Session session, Marshaller marshaller) Marshal the given object to aTextMessage.voidsetMarshaller(Marshaller marshaller) Set theMarshallerto be used by this message converter.voidsetTargetType(MessageType targetType) voidsetUnmarshaller(Unmarshaller unmarshaller) Set theUnmarshallerto be used by this message converter.jakarta.jms.MessageThis implementation marshals the given object to aTextMessageorBytesMessage.protected ObjectunmarshalFromBytesMessage(jakarta.jms.BytesMessage message, Unmarshaller unmarshaller) Unmarshal the givenBytesMessageinto an object.protected ObjectunmarshalFromMessage(jakarta.jms.Message message, Unmarshaller unmarshaller) Template method that allows for custom message unmarshalling.protected ObjectunmarshalFromTextMessage(jakarta.jms.TextMessage message, Unmarshaller unmarshaller) Unmarshal the givenTextMessageinto an object.
- 
Constructor Details- 
MarshallingMessageConverterpublic MarshallingMessageConverter()Construct a newMarshallingMessageConverterwith noMarshallerorUnmarshallerset. The marshaller must be set after construction by invokingsetMarshaller(Marshaller)andsetUnmarshaller(Unmarshaller).
- 
MarshallingMessageConverterConstruct a newMarshallingMessageConverterwith the givenMarshallerset.If the given Marshalleralso implements theUnmarshallerinterface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all Marshallerimplementations in Spring also implement theUnmarshallerinterface, so that you can safely use this constructor.- Parameters:
- marshaller- object used as marshaller and unmarshaller
- Throws:
- IllegalArgumentException- when- marshallerdoes not implement the- Unmarshallerinterface as well
 
- 
MarshallingMessageConverterConstruct a newMarshallingMessageConverterwith the given Marshaller and Unmarshaller.- Parameters:
- marshaller- the Marshaller to use
- unmarshaller- the Unmarshaller to use
 
 
- 
- 
Method Details- 
setMarshallerSet theMarshallerto be used by this message converter.
- 
setUnmarshallerSet theUnmarshallerto be used by this message converter.
- 
setTargetTypeSpecify whethertoMessage(Object, Session)should marshal to aBytesMessageor aTextMessage.The default is MessageType.BYTES, i.e. this converter marshals to aBytesMessage. Note that the default version of this converter supportsMessageType.BYTESandMessageType.TEXTonly.- See Also:
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
toMessagepublic jakarta.jms.Message toMessage(Object object, jakarta.jms.Session session) throws jakarta.jms.JMSException, MessageConversionException This implementation marshals the given object to aTextMessageorBytesMessage. The desired message type can be defined by setting the"marshalTo"property.- 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 unmarshals the givenMessageinto an object.- 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:
 
- 
marshalToTextMessageprotected jakarta.jms.TextMessage marshalToTextMessage(Object object, jakarta.jms.Session session, Marshaller marshaller) throws jakarta.jms.JMSException, IOException, XmlMappingException Marshal the given object to aTextMessage.- Parameters:
- object- the object to be marshalled
- session- current JMS session
- marshaller- the marshaller to use
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
- See Also:
 
- 
marshalToBytesMessageprotected jakarta.jms.BytesMessage marshalToBytesMessage(Object object, jakarta.jms.Session session, Marshaller marshaller) throws jakarta.jms.JMSException, IOException, XmlMappingException Marshal the given object to aBytesMessage.- Parameters:
- object- the object to be marshalled
- session- current JMS session
- marshaller- the marshaller to use
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
- See Also:
 
- 
marshalToMessageprotected jakarta.jms.Message marshalToMessage(Object object, jakarta.jms.Session session, Marshaller marshaller, MessageType targetType) throws jakarta.jms.JMSException, IOException, XmlMappingException Template method that allows for custom message marshalling. Invoked whensetTargetType(MessageType)is notMessageType.TEXTorMessageType.BYTES.The default implementation throws an IllegalArgumentException.- Parameters:
- object- the object to marshal
- session- the JMS session
- marshaller- the marshaller to use
- targetType- the target message type (other than TEXT or BYTES)
- Returns:
- the resulting message
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
 
- 
unmarshalFromTextMessageprotected Object unmarshalFromTextMessage(jakarta.jms.TextMessage message, Unmarshaller unmarshaller) throws jakarta.jms.JMSException, IOException, XmlMappingException Unmarshal the givenTextMessageinto an object.- Parameters:
- message- the message
- unmarshaller- the unmarshaller to use
- Returns:
- the unmarshalled object
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
- See Also:
 
- 
unmarshalFromBytesMessageprotected Object unmarshalFromBytesMessage(jakarta.jms.BytesMessage message, Unmarshaller unmarshaller) throws jakarta.jms.JMSException, IOException, XmlMappingException Unmarshal the givenBytesMessageinto an object.- Parameters:
- message- the message
- unmarshaller- the unmarshaller to use
- Returns:
- the unmarshalled object
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
- See Also:
 
- 
unmarshalFromMessageprotected Object unmarshalFromMessage(jakarta.jms.Message message, Unmarshaller unmarshaller) throws jakarta.jms.JMSException, IOException, XmlMappingException Template method that allows for custom message unmarshalling. Invoked whenfromMessage(Message)is invoked with a message that is not aTextMessageorBytesMessage.The default implementation throws an IllegalArgumentException.- Parameters:
- message- the message
- unmarshaller- the unmarshaller to use
- Returns:
- the unmarshalled object
- Throws:
- jakarta.jms.JMSException- if thrown by JMS methods
- IOException- in case of I/O errors
- XmlMappingException- in case of OXM mapping errors
 
 
-