Top Description Fields Constructors Methods
org.springframework.http.converter.xml

public Class MarshallingHttpMessageConverter

extends AbstractXmlHttpMessageConverter<Object>
Class Inheritance
Imports
javax.xml.transform.Result, .Source, org.springframework.beans.TypeMismatchException, org.springframework.http.HttpHeaders, .MediaType, org.springframework.lang.Nullable, org.springframework.oxm.Marshaller, .Unmarshaller, org.springframework.util.Assert

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.

Author
Arjen Poutsma
Since
3.0

Field Summary

Modifier and TypeField and Description
private Marshaller
private Unmarshaller

Constructor Summary

AccessConstructor and Description
public
MarshallingHttpMessageConverter()

Construct a new MarshallingHttpMessageConverter with no Marshaller or Unmarshaller set.

public
MarshallingHttpMessageConverter(Marshaller
object used as marshaller and unmarshaller
marshaller
)

Construct a new MarshallingMessageConverter with the given Marshaller set.

public
MarshallingHttpMessageConverter(Marshaller
the Marshaller to use
marshaller
,
Unmarshaller
the Unmarshaller to use
unmarshaller
)

Construct a new MarshallingMessageConverter with the given Marshaller and Unmarshaller.

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(Class<?>
the class to test for readability
clazz
,
MediaType
the media type to read (can be null if not specified); typically the value of a Content-Type header.
mediaType
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canRead.

Implements org.springframework.http.converter.HttpMessageConverter.canRead.

This implementation checks if the given class is supported, and if the supported media types include the given media type.
public boolean
canWrite(Class<?>
the class to test for writability
clazz
,
MediaType
the media type to write (can be null if not specified); typically the value of an Accept header.
mediaType
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.HttpMessageConverter.canWrite.

This implementation checks if the given class is supported, and if the supported media types include the given media type.
protected Object
readFromSource(Class<?>
the type of object to return
clazz
,
HttpHeaders
the HTTP input headers
headers
,
Source
the HTTP input body
source
)

Implements abstract org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.readFromSource.

Abstract template method called from read(Class, HttpInputMessage).
public void
setMarshaller(Marshaller marshaller)

Set the Marshaller to be used by this message converter.

public void
setUnmarshaller(Unmarshaller unmarshaller)

Set the Unmarshaller to be used by this message converter.

protected boolean
supports(Class<?>
the class to test for support
clazz
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.
protected boolean
supportsRepeatableWrites(Object
the object t
o
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.
protected void
writeToResult(Object
the object to write to the output message
o
,
HttpHeaders
the HTTP output headers
headers
,
Result
the HTTP output body
result
)

Implements abstract org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeToResult.

Abstract template method called from writeInternal(Object, HttpOutputMessage).
Inherited from org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter:
readInternaltransformwriteInternal

Field Detail

marshallerback to summary
private Marshaller marshaller
Annotations
@Nullable
unmarshallerback to summary
private Unmarshaller unmarshaller
Annotations
@Nullable

Constructor Detail

MarshallingHttpMessageConverterback to summary
public MarshallingHttpMessageConverter()

Construct a new MarshallingHttpMessageConverter with no Marshaller or Unmarshaller set. The Marshaller and Unmarshaller must be set after construction by invoking setMarshaller(Marshaller) and setUnmarshaller(Unmarshaller).

MarshallingHttpMessageConverterback to summary
public MarshallingHttpMessageConverter(Marshaller marshaller)

Construct a new 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.

Parameters
marshaller:Marshaller

object used as marshaller and unmarshaller

MarshallingHttpMessageConverterback to summary
public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)

Construct a new MarshallingMessageConverter with the given Marshaller and Unmarshaller.

Parameters
marshaller:Marshaller

the Marshaller to use

unmarshaller:Unmarshaller

the Unmarshaller to use

Method Detail

canReadback to summary
public boolean canRead(Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canRead.

Implements org.springframework.http.converter.HttpMessageConverter.canRead.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.canRead.

This implementation checks if the given class is supported, and if the supported media types include the given media type.

Parameters
clazz:Class<?>

Doc from org.springframework.http.converter.HttpMessageConverter.canRead.

the class to test for readability

mediaType:MediaType

Doc from org.springframework.http.converter.HttpMessageConverter.canRead.

the media type to read (can be null if not specified); typically the value of a Content-Type header.

Returns:boolean

Doc from org.springframework.http.converter.HttpMessageConverter.canRead.

true if readable; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite(Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.HttpMessageConverter.canWrite.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.canWrite.

This implementation checks if the given class is supported, and if the supported media types include the given media type.

Parameters
clazz:Class<?>

Doc from org.springframework.http.converter.HttpMessageConverter.canWrite.

the class to test for writability

mediaType:MediaType

Doc from org.springframework.http.converter.HttpMessageConverter.canWrite.

the media type to write (can be null if not specified); typically the value of an Accept header.

Returns:boolean

Doc from org.springframework.http.converter.HttpMessageConverter.canWrite.

true if writable; false otherwise

Annotations
@Override
readFromSourceback to summary
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception

Implements abstract org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.readFromSource.

Doc from org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.readFromSource.

Abstract template method called from read(Class, HttpInputMessage).

Parameters
clazz:Class<?>

the type of object to return

headers:HttpHeaders

the HTTP input headers

source:Source

the HTTP input body

Returns:Object

the converted object

Annotations
@Override
Exceptions
Exception:
in case of I/O or conversion errors
setMarshallerback to summary
public void setMarshaller(Marshaller marshaller)

Set the Marshaller to be used by this message converter.

setUnmarshallerback to summary
public void setUnmarshaller(Unmarshaller unmarshaller)

Set the Unmarshaller to be used by this message converter.

supportsback to summary
protected boolean supports(Class<?> clazz)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.

Parameters
clazz:Class<?>

the class to test for support

Returns:boolean

true if supported; false otherwise

Annotations
@Override
supportsRepeatableWritesback to summary
protected boolean supportsRepeatableWrites(Object o)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.

Default implementation returns false.

Parameters
o:Object

the object t

Returns:boolean

true if t can be written repeatedly; false otherwise

Annotations
@Override
writeToResultback to summary
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws Exception

Implements abstract org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeToResult.

Doc from org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.writeToResult.

Abstract template method called from writeInternal(Object, HttpOutputMessage).

Parameters
o:Object

the object to write to the output message

headers:HttpHeaders

the HTTP output headers

result:Result

the HTTP output body

Annotations
@Override
Exceptions
Exception:
in case of I/O or conversion errors