Class MarshallingMessageConverter
- java.lang.Object
- org.springframework.messaging.converter.AbstractMessageConverter
- org.springframework.messaging.converter.MarshallingMessageConverter
- All Implemented Interfaces:
MessageConverter,SmartMessageConverter
public class MarshallingMessageConverter extends AbstractMessageConverter
Implementation ofMessageConverterthat can read and write XML using Spring'sMarshallerandUnmarshallerabstractions.This converter requires a
MarshallerandUnmarshallerbefore it can be used. These can be injected by the constructor or bean properties.- Since:
- 4.2
- Author:
- Arjen Poutsma
- See Also:
Marshaller,Unmarshaller
Field Summary
Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter
logger
Constructor Summary
Constructors Constructor Description MarshallingMessageConverter()Default construct allowing forsetMarshaller(Marshaller)and/orsetUnmarshaller(Unmarshaller)to be invoked separately.MarshallingMessageConverter(Marshaller marshaller)Constructor withMarshaller.MarshallingMessageConverter(MimeType... supportedMimeTypes)Constructor with a given list of MIME types to support.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanConvertFrom(Message<?> message, Class<?> targetClass)protected booleancanConvertTo(Object payload, MessageHeaders headers)protected ObjectconvertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)Convert the message payload from serialized form to an Object.protected ObjectconvertToInternal(Object payload, MessageHeaders headers, Object conversionHint)Convert the payload object to serialized form.MarshallergetMarshaller()Return the configured Marshaller.UnmarshallergetUnmarshaller()Return the configured unmarshaller.voidsetMarshaller(Marshaller marshaller)Set theMarshallerto be used by this message converter.voidsetUnmarshaller(Unmarshaller unmarshaller)Set theUnmarshallerto be used by this message converter.protected booleansupports(Class<?> clazz)Whether the given class is supported by this converter.Methods inherited from class org.springframework.messaging.converter.AbstractMessageConverter
convertFromInternal, convertToInternal, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage
Constructor Detail
MarshallingMessageConverter
public MarshallingMessageConverter()
Default construct allowing forsetMarshaller(Marshaller)and/orsetUnmarshaller(Unmarshaller)to be invoked separately.
MarshallingMessageConverter
public MarshallingMessageConverter(MimeType... supportedMimeTypes)
Constructor with a given list of MIME types to support.- Parameters:
supportedMimeTypes- the MIME types
MarshallingMessageConverter
public MarshallingMessageConverter(Marshaller marshaller)
Constructor withMarshaller. If the givenMarshalleralso implementsUnmarshaller, it is also used for unmarshalling.Note that all
Marshallerimplementations in Spring also implementUnmarshallerso that you can safely use this constructor.- Parameters:
marshaller- object used as marshaller and unmarshaller
Method Detail
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshallerto be used by this message converter.
getMarshaller
public Marshaller getMarshaller()
Return the configured Marshaller.
setUnmarshaller
public void setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshallerto be used by this message converter.
getUnmarshaller
public Unmarshaller getUnmarshaller()
Return the configured unmarshaller.
canConvertFrom
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass)
- Overrides:
canConvertFromin classAbstractMessageConverter
canConvertTo
protected boolean canConvertTo(Object payload, MessageHeaders headers)
- Overrides:
canConvertToin classAbstractMessageConverter
supports
protected boolean supports(Class<?> clazz)
Description copied from class:AbstractMessageConverterWhether the given class is supported by this converter.- Specified by:
supportsin classAbstractMessageConverter- Parameters:
clazz- the class to test for support- Returns:
trueif supported;falseotherwise
convertFromInternal
protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)
Description copied from class:AbstractMessageConverterConvert the message payload from serialized form to an Object.- Overrides:
convertFromInternalin classAbstractMessageConverter- Parameters:
message- the input messagetargetClass- the target class for the conversionconversionHint- an extra object passed to theMessageConverter, e.g. the associatedMethodParameter(may benull}- Returns:
- the result of the conversion, or
nullif the converter cannot perform the conversion
convertToInternal
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint)
Description copied from class:AbstractMessageConverterConvert the payload object to serialized form.- Overrides:
convertToInternalin classAbstractMessageConverter- Parameters:
payload- the Object to convertheaders- optional headers for the message (may benull)conversionHint- an extra object passed to theMessageConverter, e.g. the associatedMethodParameter(may benull}- Returns:
- the resulting payload for the message, or
nullif the converter cannot perform the conversion