public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessageConverter<Object>
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.
MarshallingHttpMessageConverter
logger
Constructor and Description |
---|
Jaxb2RootElementHttpMessageConverter() |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(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(Class<?> clazz,
MediaType mediaType)
|
boolean |
isProcessExternalEntities()
Return whether XML external entities are allowed.
|
boolean |
isSupportDtd()
Return whether DTD parsing is supported.
|
protected Source |
processSource(Source source) |
protected Object |
readFromSource(Class<?> clazz,
HttpHeaders headers,
Source source)
Abstract template method called from
AbstractHttpMessageConverter.read(Class, HttpInputMessage) . |
void |
setProcessExternalEntities(boolean processExternalEntities)
Indicate whether external XML entities are processed when converting to a Source.
|
void |
setSupportDtd(boolean supportDtd)
Indicate whether DTD parsing should be supported.
|
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 from
AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage) . |
createMarshaller, createUnmarshaller, customizeMarshaller, customizeUnmarshaller, getJaxbContext
readInternal, transform, writeInternal
addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
public Jaxb2RootElementHttpMessageConverter()
public void setSupportDtd(boolean supportDtd)
Default is false
meaning that DTD is disabled.
public boolean isSupportDtd()
public void setProcessExternalEntities(boolean processExternalEntities)
Default is false
, meaning that external entities are not resolved.
Note: setting this option to true
also
automatically sets setSupportDtd(boolean)
to true
.
public boolean isProcessExternalEntities()
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConverter
canRead
in interface HttpMessageConverter<Object>
canRead
in class AbstractHttpMessageConverter<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(Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConverter
canWrite
in interface HttpMessageConverter<Object>
canWrite
in class AbstractHttpMessageConverter<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(Class<?> clazz)
AbstractHttpMessageConverter
supports
in class AbstractHttpMessageConverter<Object>
clazz
- the class to test for supporttrue
if supported; false
otherwiseprotected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException
AbstractXmlHttpMessageConverter
AbstractHttpMessageConverter.read(Class, HttpInputMessage)
.readFromSource
in class AbstractXmlHttpMessageConverter<Object>
clazz
- the type of object to returnheaders
- the HTTP input headerssource
- the HTTP input bodyIOException
- in case of I/O errorsprotected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException
AbstractXmlHttpMessageConverter
AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)
.writeToResult
in class AbstractXmlHttpMessageConverter<Object>
o
- the object to write to the output messageheaders
- the HTTP output headersresult
- the HTTP output bodyIOException
- in case of I/O errors