Package org.springframework.http.converter.xml

# Class Jaxb2RootElementHttpMessageConverter

java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<T>
org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<T>
org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter<Object>
org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter

All Implemented Interfaces:
  `HttpMessageConverter<Object>`

public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessageConverter<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:
  - `MarshallingHttpMessageConverter`

## Field Summary

### Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter

`logger`

## Constructor Summary

Constructors
Constructor
Description
`Jaxb2RootElementHttpMessageConverter()`

## Method Summary

Modifier and Type
Method
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)`
This implementation checks if the given class is supported, and if the supported media types include the given media type.
`boolean`
`isProcessExternalEntities()`
Return whether XML external entities are allowed.
`boolean`
`isSupportDtd()`
Return whether DTD parsing is supported.
`protected Source`
`processSource(Source source, Charset charset)`
Process `source` with `charset`.
`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 boolean`
`supportsRepeatableWrites(Object o)`
Indicates whether this message converter can write the given object multiple times.
`protected void`
`writeToResult(Object value, HttpHeaders headers, Result result)`
Abstract template method called from `AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)`.

### Methods inherited from class org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter

`createMarshaller, createUnmarshaller, customizeMarshaller, customizeUnmarshaller, detectCharset, getJaxbContext`

### Methods inherited from class org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter

`readInternal, transform, writeInternal`

### Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter

`addDefaultHeaders, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.http.converter.HttpMessageConverter

`getSupportedMediaTypes`

## Constructor Details

### Jaxb2RootElementHttpMessageConverter

public Jaxb2RootElementHttpMessageConverter()

## Method Details

### setSupportDtd

public void setSupportDtd(boolean supportDtd)
Indicate whether DTD parsing should be supported.

Default is `false` meaning 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 `true` also automatically sets `setSupportDtd(boolean)` to `true`.

### isProcessExternalEntities

public boolean isProcessExternalEntities()
Return whether XML external entities are allowed.

### canRead

public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
Description copied from class: `AbstractHttpMessageConverter`
This implementation checks if the given class is supported, and if the supported media types include the given media type.

Specified by:
  `canRead` in interface `HttpMessageConverter<Object>`
Overrides:
  `canRead` in class `AbstractHttpMessageConverter<Object>`
Parameters:
  `clazz` - the class to test for readability
  `mediaType` - the media type to read (can be `null` if not specified); typically the value of a `Content-Type` header.
Returns:
  `true` if readable; `false` otherwise

### canWrite

public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType)
Description copied from class: `AbstractHttpMessageConverter`
This implementation checks if the given class is supported, and if the supported media types include the given media type.

Specified by:
  `canWrite` in interface `HttpMessageConverter<Object>`
Overrides:
  `canWrite` in class `AbstractHttpMessageConverter<Object>`
Parameters:
  `clazz` - the class to test for writability
  `mediaType` - the media type to write (can be `null` if not specified); typically the value of an `Accept` header.
Returns:
  `true` if writable; `false` otherwise

### supports

protected boolean supports(Class<?> clazz)
Description copied from class: `AbstractHttpMessageConverter`
Indicates whether the given class is supported by this converter.

Specified by:
  `supports` in class `AbstractHttpMessageConverter<Object>`
Parameters:
  `clazz` - the class to test for support
Returns:
  `true` if supported; `false` otherwise

### readFromSource

protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception
Description copied from class: `AbstractXmlHttpMessageConverter`
Abstract template method called from `AbstractHttpMessageConverter.read(Class, HttpInputMessage)`.

Specified by:
  `readFromSource` in class `AbstractXmlHttpMessageConverter<Object>`
Parameters:
  `clazz` - the type of object to return
  `headers` - the HTTP input headers
  `source` - the HTTP input body
Returns:
  the converted object
Throws:
  `Exception` - in case of I/O or conversion errors

### processSource

protected Source processSource(Source source, @Nullable Charset charset)
Process `source` with `charset`.

Parameters:
  `source` - source to process
  `charset` - charset to use
Returns:
  source
Since:
  6.2.8

### writeToResult

protected void writeToResult(Object value, HttpHeaders headers, Result result) throws Exception
Description copied from class: `AbstractXmlHttpMessageConverter`
Abstract template method called from `AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage)`.

Specified by:
  `writeToResult` in class `AbstractXmlHttpMessageConverter<Object>`
Parameters:
  `value` - the object to write to the output message
  `headers` - the HTTP output headers
  `result` - the HTTP output body
Throws:
  `Exception` - in case of I/O or conversion errors

### supportsRepeatableWrites

protected boolean supportsRepeatableWrites(Object o)
Description copied from class: `AbstractHttpMessageConverter`
Indicates whether this message converter can write the given object multiple times.

The default implementation returns `false`.

Overrides:
  `supportsRepeatableWrites` in class `AbstractHttpMessageConverter<Object>`
Parameters:
  `o` - the object t
Returns:
  `true` if `t` can be written repeatedly; `false` otherwise