类 MarshallingHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<T>
- org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<Object>
- org.springframework.http.converter.xml.MarshallingHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<Object>
public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object>
Implementation ofHttpMessageConverter
that can read and write XML using Spring'sMarshaller
andUnmarshaller
abstractions.This converter requires a
Marshaller
andUnmarshaller
before it can be used. These can be injected by the constructor or bean properties.By default, this converter supports
text/xml
andapplication/xml
. This can be overridden by setting thesupportedMediaTypes
property.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma
字段概要
从类继承的字段 org.springframework.http.converter.AbstractHttpMessageConverter
logger
构造器概要
构造器 构造器 说明 MarshallingHttpMessageConverter()
MarshallingHttpMessageConverter(Marshaller marshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
set.MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
andUnmarshaller
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
canRead(Class<?> clazz, MediaType mediaType)
This implementation checks if the given class is supported, and if the supported media typesinclude the given media type.boolean
canWrite(Class<?> clazz, MediaType mediaType)
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
supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.protected void
writeToResult(Object o, HttpHeaders headers, Result result)
Abstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.从类继承的方法 org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter
readInternal, transform, writeInternal
从类继承的方法 org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
构造器详细资料
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
public MarshallingHttpMessageConverter(Marshaller marshaller)
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.- 参数:
marshaller
- object used as marshaller and unmarshaller
MarshallingHttpMessageConverter
public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller)
Construct a newMarshallingMessageConverter
with the givenMarshaller
andUnmarshaller
.- 参数:
marshaller
- the Marshaller to useunmarshaller
- the Unmarshaller to use
方法详细资料
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this message converter.
setUnmarshaller
public void setUnmarshaller(Unmarshaller unmarshaller)
Set theUnmarshaller
to be used by this message converter.
canRead
public boolean canRead(Class<?> clazz, MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media typesinclude the given media type.- 指定者:
canRead
在接口中HttpMessageConverter<Object>
- 覆盖:
canRead
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for readabilitymediaType
- the media type to read (can benull
if not specified); typically the value of aContent-Type
header.- 返回:
true
if readable;false
otherwise
canWrite
public boolean canWrite(Class<?> clazz, MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.- 指定者:
canWrite
在接口中HttpMessageConverter<Object>
- 覆盖:
canWrite
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for writabilitymediaType
- the media type to write (can benull
if not specified); typically the value of anAccept
header.- 返回:
true
if writable;false
otherwise
supports
protected boolean supports(Class<?> clazz)
从类复制的说明:AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.- 指定者:
supports
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for support- 返回:
true
if supported;false
otherwise
readFromSource
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException
从类复制的说明:AbstractXmlHttpMessageConverter
Abstract template method called fromAbstractHttpMessageConverter.read(Class, HttpInputMessage)
.- 指定者:
readFromSource
在类中AbstractXmlHttpMessageConverter<Object>
- 参数:
clazz
- the type of object to returnheaders
- the HTTP input headerssource
- the HTTP input body- 返回:
- the converted object
- 抛出:
IOException
- in case of I/O errors
writeToResult
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException
从类复制的说明:AbstractXmlHttpMessageConverter
Abstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.- 指定者:
writeToResult
在类中AbstractXmlHttpMessageConverter<Object>
- 参数:
o
- the object to write to the output messageheaders
- the HTTP output headersresult
- the HTTP output body- 抛出:
IOException
- in case of I/O errors