Class MarshallingHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<T>
org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<Object>
org.springframework.http.converter.xml.MarshallingHttpMessageConverter
- All Implemented Interfaces:
HttpMessageConverter<Object>
Implementation of
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.
- Since:
- 3.0
- Author:
- Arjen Poutsma
-
Field Summary
Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger
-
Constructor Summary
ConstructorDescriptionMarshallingHttpMessageConverter
(Marshaller marshaller) Construct a newMarshallingMessageConverter
with the givenMarshaller
set.MarshallingHttpMessageConverter
(Marshaller marshaller, Unmarshaller unmarshaller) Construct a newMarshallingMessageConverter
with the givenMarshaller
andUnmarshaller
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
This implementation checks if the given class is supported, and if the supported media types include the given media type.boolean
protected Object
readFromSource
(Class<?> clazz, HttpHeaders headers, Source source) Abstract template method called fromAbstractHttpMessageConverter.read(Class, HttpInputMessage)
.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
Indicates whether the given class is supported by this converter.protected boolean
Indicates whether this message converter can write the given object multiple times.protected void
writeToResult
(Object o, HttpHeaders headers, Result result) Abstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.Methods inherited from class org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter
readInternal, transform, writeInternal
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.converter.HttpMessageConverter
getSupportedMediaTypes
-
Constructor Details
-
MarshallingHttpMessageConverter
public MarshallingHttpMessageConverter()Construct a newMarshallingHttpMessageConverter
with noMarshaller
orUnmarshaller
set. The Marshaller and Unmarshaller must be set after construction by invokingsetMarshaller(Marshaller)
andsetUnmarshaller(Unmarshaller)
. -
MarshallingHttpMessageConverter
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.If the given
Marshaller
also implements theUnmarshaller
interface, it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.Note that all
Marshaller
implementations in Spring also implement theUnmarshaller
interface, so that you can safely use this constructor.- Parameters:
marshaller
- object used as marshaller and unmarshaller
-
MarshallingHttpMessageConverter
Construct a newMarshallingMessageConverter
with the givenMarshaller
andUnmarshaller
.- Parameters:
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to use
-
-
Method Details
-
setMarshaller
Set theMarshaller
to be used by this message converter. -
setUnmarshaller
Set theUnmarshaller
to be used by this message converter. -
canRead
Description copied from class:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.- Specified by:
canRead
in interfaceHttpMessageConverter<Object>
- Overrides:
canRead
in classAbstractHttpMessageConverter<Object>
- Parameters:
clazz
- the class to test for readabilitymediaType
- the media type to read (can benull
if not specified); typically the value of aContent-Type
header.- Returns:
true
if readable;false
otherwise
-
canWrite
Description copied from class:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.- Specified by:
canWrite
in interfaceHttpMessageConverter<Object>
- Overrides:
canWrite
in classAbstractHttpMessageConverter<Object>
- Parameters:
clazz
- the class to test for writabilitymediaType
- the media type to write (can benull
if not specified); typically the value of anAccept
header.- Returns:
true
if writable;false
otherwise
-
supports
Description copied from class:AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.- Specified by:
supports
in classAbstractHttpMessageConverter<Object>
- Parameters:
clazz
- the class to test for support- Returns:
true
if supported;false
otherwise
-
readFromSource
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception Description copied from class:AbstractXmlHttpMessageConverter
Abstract template method called fromAbstractHttpMessageConverter.read(Class, HttpInputMessage)
.- Specified by:
readFromSource
in classAbstractXmlHttpMessageConverter<Object>
- Parameters:
clazz
- the type of object to returnheaders
- the HTTP input headerssource
- the HTTP input body- Returns:
- the converted object
- Throws:
Exception
- in case of I/O or conversion errors
-
writeToResult
Description copied from class:AbstractXmlHttpMessageConverter
Abstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.- Specified by:
writeToResult
in classAbstractXmlHttpMessageConverter<Object>
- Parameters:
o
- the object to write to the output messageheaders
- the HTTP output headersresult
- the HTTP output body- Throws:
Exception
- in case of I/O or conversion errors
-
supportsRepeatableWrites
Description copied from class:AbstractHttpMessageConverter
Indicates whether this message converter can write the given object multiple times.Default implementation returns
false
.- Overrides:
supportsRepeatableWrites
in classAbstractHttpMessageConverter<Object>
- Parameters:
o
- the object t- Returns:
true
ift
can be written repeatedly;false
otherwise
-