public class MarshallingMessageConverter extends AbstractMessageConverter
MessageConverter
that can read and write XML using Spring's
Marshaller
and Unmarshaller
abstractions.
This converter requires a Marshaller
and Unmarshaller
before it can
be used. These can be injected by the constructor or bean properties.
logger
Constructor and Description |
---|
MarshallingMessageConverter()
Default construct allowing for
setMarshaller(Marshaller) and/or
setUnmarshaller(Unmarshaller) to be invoked separately. |
MarshallingMessageConverter(Marshaller marshaller)
Constructor with
Marshaller . |
MarshallingMessageConverter(MimeType... supportedMimeTypes)
Constructor with a given list of MIME types to support.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canConvertFrom(Message<?> message,
java.lang.Class<?> targetClass) |
protected boolean |
canConvertTo(java.lang.Object payload,
MessageHeaders headers) |
protected java.lang.Object |
convertFromInternal(Message<?> message,
java.lang.Class<?> targetClass,
java.lang.Object conversionHint)
Convert the message payload from serialized form to an Object.
|
protected java.lang.Object |
convertToInternal(java.lang.Object payload,
MessageHeaders headers,
java.lang.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 the
Marshaller to be used by this message converter. |
void |
setUnmarshaller(Unmarshaller unmarshaller)
Set the
Unmarshaller to be used by this message converter. |
protected boolean |
supports(java.lang.Class<?> clazz)
Whether the given class is supported by this converter.
|
fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessage
public MarshallingMessageConverter()
setMarshaller(Marshaller)
and/or
setUnmarshaller(Unmarshaller)
to be invoked separately.public MarshallingMessageConverter(MimeType... supportedMimeTypes)
supportedMimeTypes
- the MIME typespublic MarshallingMessageConverter(Marshaller marshaller)
Marshaller
. If the given Marshaller
also
implements Unmarshaller
, it is also used for unmarshalling.
Note that all Marshaller
implementations in Spring also implement
Unmarshaller
so that you can safely use this constructor.
marshaller
- object used as marshaller and unmarshallerpublic void setMarshaller(@Nullable Marshaller marshaller)
Marshaller
to be used by this message converter.@Nullable public Marshaller getMarshaller()
public void setUnmarshaller(@Nullable Unmarshaller unmarshaller)
Unmarshaller
to be used by this message converter.@Nullable public Unmarshaller getUnmarshaller()
protected boolean canConvertFrom(Message<?> message, java.lang.Class<?> targetClass)
canConvertFrom
in class AbstractMessageConverter
protected boolean canConvertTo(java.lang.Object payload, @Nullable MessageHeaders headers)
canConvertTo
in class AbstractMessageConverter
protected boolean supports(java.lang.Class<?> clazz)
AbstractMessageConverter
supports
in class AbstractMessageConverter
clazz
- the class to test for supporttrue
if supported; false
otherwise@Nullable protected java.lang.Object convertFromInternal(Message<?> message, java.lang.Class<?> targetClass, @Nullable java.lang.Object conversionHint)
AbstractMessageConverter
convertFromInternal
in class AbstractMessageConverter
message
- the input messagetargetClass
- the target class for the conversionconversionHint
- an extra object passed to the MessageConverter
,
e.g. the associated MethodParameter
(may be null
}null
if the converter cannot
perform the conversion@Nullable protected java.lang.Object convertToInternal(java.lang.Object payload, @Nullable MessageHeaders headers, @Nullable java.lang.Object conversionHint)
AbstractMessageConverter
convertToInternal
in class AbstractMessageConverter
payload
- the Object to convertheaders
- optional headers for the message (may be null
)conversionHint
- an extra object passed to the MessageConverter
,
e.g. the associated MethodParameter
(may be null
}null
if the converter
cannot perform the conversion