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

public Class Jaxb2RootElementHttpMessageConverter

extends AbstractJaxb2HttpMessageConverter<Object>
Class Inheritance
Imports
java.io.StringReader, javax.xml.parsers.ParserConfigurationException, .SAXParser, .SAXParserFactory, javax.xml.transform.Result, .Source, javax.xml.transform.sax.SAXSource, javax.xml.transform.stream.StreamSource, jakarta.xml.bind.JAXBElement, .JAXBException, .MarshalException, .Marshaller, .PropertyException, .UnmarshalException, .Unmarshaller, jakarta.xml.bind.annotation.XmlRootElement, .XmlType, org.xml.sax.EntityResolver, .InputSource, .SAXException, .XMLReader, org.springframework.core.annotation.AnnotationUtils, org.springframework.http.HttpHeaders, .MediaType, org.springframework.http.converter.HttpMessageConversionException, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

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.

Authors
Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev
Since
3.0
See Also
MarshallingHttpMessageConverter

Field Summary

Modifier and TypeField and Description
private static final EntityResolver
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

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.

public boolean
isProcessExternalEntities()

Return whether XML external entities are allowed.

public boolean
isSupportDtd()

Return whether DTD parsing is supported.

protected Source
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).

private void
setCharset(MediaType contentType, Marshaller marshaller)

public void
setProcessExternalEntities(boolean processExternalEntities)

Indicate whether external XML entities are processed when converting to a Source.

public void
setSupportDtd(boolean supportDtd)

Indicate whether DTD parsing should be supported.

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.AbstractJaxb2HttpMessageConverter:
createMarshallercreateUnmarshallercustomizeMarshallercustomizeUnmarshallergetJaxbContext

Field Detail

NO_OP_ENTITY_RESOLVERback to summary
private static final EntityResolver NO_OP_ENTITY_RESOLVER
processExternalEntitiesback to summary
private boolean processExternalEntities
supportDtdback to summary
private boolean supportDtd

Constructor Detail

Jaxb2RootElementHttpMessageConverterback to summary
public Jaxb2RootElementHttpMessageConverter()

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
isProcessExternalEntitiesback to summary
public boolean isProcessExternalEntities()

Return whether XML external entities are allowed.

isSupportDtdback to summary
public boolean isSupportDtd()

Return whether DTD parsing is supported.

processSourceback to summary
protected Source processSource(Source source)
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
setCharsetback to summary
private void setCharset(MediaType contentType, Marshaller marshaller) throws PropertyException
setProcessExternalEntitiesback to summary
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 true also automatically sets setSupportDtd to true.

setSupportDtdback to summary
public void setSupportDtd(boolean supportDtd)

Indicate whether DTD parsing should be supported.

Default is false meaning that DTD is disabled.

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