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.
Marshaller,
Unmarshallerlogger| 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,
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 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(Class<?> clazz)
Whether the given class is supported by this converter.
|
addSupportedMimeTypes, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, supportsMimeType, toMessage, toMessagepublic 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, Class<?> targetClass)
canConvertFrom in class AbstractMessageConverterprotected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers)
canConvertTo in class AbstractMessageConverterprotected boolean supports(Class<?> clazz)
AbstractMessageConvertersupports in class AbstractMessageConverterclazz - the class to test for supporttrue if supported; false otherwise@Nullable protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint)
AbstractMessageConverterconvertFromInternal in class AbstractMessageConvertermessage - 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 Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint)
AbstractMessageConverterconvertToInternal in class AbstractMessageConverterpayload - 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