Class Jaxb2RootElementHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<Object>
org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter<Object>
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
- All Implemented Interfaces:
HttpMessageConverter<Object>
Implementation of
HttpMessageConverter that can read and write XML using JAXB2.
This converter can read classes annotated with XmlRootElement and
XmlType, and write classes annotated with XmlRootElement,
or subclasses thereof.
Note: When using Spring's Marshaller/Unmarshaller abstractions from spring-oxm,
you should use the MarshallingHttpMessageConverter instead.
- Since:
- 3.0
- Author:
- Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class AbstractHttpMessageConverter
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis implementation checks if the given class is supported, and if the supported media types include the given media type.booleanbooleanReturn whether XML external entities are allowed.booleanReturn whether DTD parsing is supported.protected SourceprocessSource(Source source, @Nullable Charset charset) Processsourcewithcharset.protected ObjectreadFromSource(Class<?> clazz, HttpHeaders headers, Source source) Abstract template method called fromAbstractHttpMessageConverter.read(Class, HttpInputMessage).voidsetProcessExternalEntities(boolean processExternalEntities) Indicate whether external XML entities are processed when converting to a Source.voidsetSupportDtd(boolean supportDtd) Indicate whether DTD parsing should be supported.protected booleanIndicates whether the given class is supported by this converter.protected booleanIndicates whether this message converter can write the given object multiple times.protected voidwriteToResult(Object value, HttpHeaders headers, Result result) Abstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage).Methods inherited from class AbstractJaxb2HttpMessageConverter
createMarshaller, createUnmarshaller, customizeMarshaller, customizeUnmarshaller, detectCharset, getJaxbContextMethods inherited from class AbstractXmlHttpMessageConverter
readInternal, transform, writeInternalMethods inherited from class AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, writeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpMessageConverter
getSupportedMediaTypes
-
Constructor Details
-
Jaxb2RootElementHttpMessageConverter
public Jaxb2RootElementHttpMessageConverter()
-
-
Method Details
-
setSupportDtd
public void setSupportDtd(boolean supportDtd) Indicate whether DTD parsing should be supported.Default is
falsemeaning that DTD is disabled. -
isSupportDtd
public boolean isSupportDtd()Return whether DTD parsing is supported. -
setProcessExternalEntities
public void setProcessExternalEntities(boolean processExternalEntities) Indicate whether external XML entities are processed when converting to a Source.Default is
false, meaning that external entities are not resolved.Note: setting this option to
truealso automatically setssetSupportDtd(boolean)totrue. -
isProcessExternalEntities
public boolean isProcessExternalEntities()Return whether XML external entities are allowed. -
canRead
Description copied from class:AbstractHttpMessageConverterThis implementation checks if the given class is supported, and if the supported media types include the given media type.- Specified by:
canReadin interfaceHttpMessageConverter<Object>- Overrides:
canReadin classAbstractHttpMessageConverter<Object>- Parameters:
clazz- the class to test for readabilitymediaType- the media type to read (can benullif not specified); typically the value of aContent-Typeheader.- Returns:
trueif readable;falseotherwise
-
canWrite
Description copied from class:AbstractHttpMessageConverterThis implementation checks if the given class is supported, and if the supported media types include the given media type.- Specified by:
canWritein interfaceHttpMessageConverter<Object>- Overrides:
canWritein classAbstractHttpMessageConverter<Object>- Parameters:
clazz- the class to test for writabilitymediaType- the media type to write (can benullif not specified); typically the value of anAcceptheader.- Returns:
trueif writable;falseotherwise
-
supports
Description copied from class:AbstractHttpMessageConverterIndicates whether the given class is supported by this converter.- Specified by:
supportsin classAbstractHttpMessageConverter<Object>- Parameters:
clazz- the class to test for support- Returns:
trueif supported;falseotherwise
-
readFromSource
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception Description copied from class:AbstractXmlHttpMessageConverterAbstract template method called fromAbstractHttpMessageConverter.read(Class, HttpInputMessage).- Specified by:
readFromSourcein 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
-
processSource
-
writeToResult
Description copied from class:AbstractXmlHttpMessageConverterAbstract template method called fromAbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage).- Specified by:
writeToResultin classAbstractXmlHttpMessageConverter<Object>- Parameters:
value- 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:AbstractHttpMessageConverterIndicates whether this message converter can write the given object multiple times.The default implementation returns
false.- Overrides:
supportsRepeatableWritesin classAbstractHttpMessageConverter<Object>- Parameters:
o- the object t- Returns:
trueiftcan be written repeatedly;falseotherwise
-