public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<java.lang.Object>
HttpMessageConverter
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.
By default, this converter supports text/xml
and application/xml
. This can be
overridden by setting the supportedMediaTypes
property.
logger
Constructor and Description |
---|
MarshallingHttpMessageConverter()
|
MarshallingHttpMessageConverter(Marshaller marshaller)
Construct a new
MarshallingMessageConverter with the given Marshaller set. |
MarshallingHttpMessageConverter(Marshaller marshaller,
Unmarshaller unmarshaller)
Construct a new
MarshallingMessageConverter with the given
Marshaller and Unmarshaller . |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(java.lang.Class<?> clazz,
MediaType mediaType)
This implementation checks if the given class is supported,
and if the supported media types
include the given media type.
|
boolean |
canWrite(java.lang.Class<?> clazz,
MediaType mediaType)
|
protected java.lang.Object |
readFromSource(java.lang.Class<?> clazz,
HttpHeaders headers,
javax.xml.transform.Source source)
Abstract template method called from
AbstractHttpMessageConverter.read(Class, HttpInputMessage) . |
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)
Indicates whether the given class is supported by this converter.
|
protected void |
writeToResult(java.lang.Object o,
HttpHeaders headers,
javax.xml.transform.Result result)
Abstract template method called from
AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage) . |
readInternal, transform, writeInternal
addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
public MarshallingHttpMessageConverter()
MarshallingHttpMessageConverter
with no Marshaller
or
Unmarshaller
set. The Marshaller and Unmarshaller must be set after construction
by invoking setMarshaller(Marshaller)
and setUnmarshaller(Unmarshaller)
.public MarshallingHttpMessageConverter(Marshaller marshaller)
MarshallingMessageConverter
with the given Marshaller
set.
If the given Marshaller
also implements the Unmarshaller
interface,
it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.
Note that all Marshaller
implementations in Spring also implement the
Unmarshaller
interface, so that you can safely use this constructor.
marshaller
- object used as marshaller and unmarshallerpublic MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
MarshallingMessageConverter
with the given
Marshaller
and Unmarshaller
.marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to usepublic void setMarshaller(Marshaller marshaller)
Marshaller
to be used by this message converter.public void setUnmarshaller(Unmarshaller unmarshaller)
Unmarshaller
to be used by this message converter.public boolean canRead(java.lang.Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConverter
canRead
in interface HttpMessageConverter<java.lang.Object>
canRead
in class AbstractHttpMessageConverter<java.lang.Object>
clazz
- the class to test for readabilitymediaType
- the media type to read (can be null
if not specified);
typically the value of a Content-Type
header.true
if readable; false
otherwisepublic boolean canWrite(java.lang.Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConverter
canWrite
in interface HttpMessageConverter<java.lang.Object>
canWrite
in class AbstractHttpMessageConverter<java.lang.Object>
clazz
- the class to test for writabilitymediaType
- the media type to write (can be null
if not specified);
typically the value of an Accept
header.true
if writable; false
otherwiseprotected boolean supports(java.lang.Class<?> clazz)
AbstractHttpMessageConverter
supports
in class AbstractHttpMessageConverter<java.lang.Object>
clazz
- the class to test for supporttrue
if supported; false
otherwiseprotected java.lang.Object readFromSource(java.lang.Class<?> clazz, HttpHeaders headers, javax.xml.transform.Source source) throws java.lang.Exception
AbstractXmlHttpMessageConverter
AbstractHttpMessageConverter.read(Class, HttpInputMessage)
.readFromSource
in class AbstractXmlHttpMessageConverter<java.lang.Object>
clazz
- the type of object to returnheaders
- the HTTP input headerssource
- the HTTP input bodyjava.lang.Exception
- in case of I/O or conversion errorsprotected void writeToResult(java.lang.Object o, HttpHeaders headers, javax.xml.transform.Result result) throws java.lang.Exception
AbstractXmlHttpMessageConverter
AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.writeToResult
in class AbstractXmlHttpMessageConverter<java.lang.Object>
o
- the object to write to the output messageheaders
- the HTTP output headersresult
- the HTTP output bodyjava.lang.Exception
- in case of I/O or conversion errors