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 ofMessageConverter
that can read and write XML using Spring'sMarshaller
andUnmarshaller
abstractions.This converter requires a
Marshaller
andUnmarshaller
before 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 boolean
canConvertFrom(Message<?> message, Class<?> targetClass)
protected boolean
canConvertTo(Object payload, MessageHeaders headers)
protected Object
convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint)
Convert the message payload from serialized form to an Object.protected Object
convertToInternal(Object payload, MessageHeaders headers, Object conversionHint)
Convert the payload object to serialized form.Marshaller
getMarshaller()
Return the configured Marshaller.Unmarshaller
getUnmarshaller()
Return the configured unmarshaller.void
setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.void
setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.protected boolean
supports(Class<?> clazz)
Whether the given class is supported by this converter.Methods inherited from class org.springframework.messaging.converter.AbstractMessageConverter
addSupportedMimeTypes, 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 givenMarshaller
also implementsUnmarshaller
, it is also used for unmarshalling.Note that all
Marshaller
implementations in Spring also implementUnmarshaller
so that you can safely use this constructor.- Parameters:
marshaller
- object used as marshaller and unmarshaller
Method Detail
setMarshaller
public void setMarshaller(@Nullable Marshaller marshaller)
Set theMarshaller
to be used by this message converter.
getMarshaller
@Nullable public Marshaller getMarshaller()
Return the configured Marshaller.
setUnmarshaller
public void setUnmarshaller(@Nullable Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.
getUnmarshaller
@Nullable public Unmarshaller getUnmarshaller()
Return the configured unmarshaller.
canConvertFrom
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass)
- Overrides:
canConvertFrom
in classAbstractMessageConverter
canConvertTo
protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers)
- Overrides:
canConvertTo
in classAbstractMessageConverter
supports
protected boolean supports(Class<?> clazz)
Description copied from class:AbstractMessageConverter
Whether the given class is supported by this converter.- Specified by:
supports
in classAbstractMessageConverter
- Parameters:
clazz
- the class to test for support- Returns:
true
if supported;false
otherwise
convertFromInternal
@Nullable protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint)
Description copied from class:AbstractMessageConverter
Convert the message payload from serialized form to an Object.- Overrides:
convertFromInternal
in 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
null
if the converter cannot perform the conversion
convertToInternal
@Nullable protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint)
Description copied from class:AbstractMessageConverter
Convert the payload object to serialized form.- Overrides:
convertToInternal
in 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
null
if the converter cannot perform the conversion