org.springframework.http.converter.xml

## Class AbstractXmlHttpMessageConverter<T>

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

- All Implemented Interfaces:
    HttpMessageConverter<T>
  Direct Known Subclasses:
    AbstractJaxb2HttpMessageConverter, MarshallingHttpMessageConverter

      public abstract class AbstractXmlHttpMessageConverter<T>
      extends AbstractHttpMessageConverter<T>

  Abstract base class for `HttpMessageConverters` that convert from/to XML.

  By default, subclasses of this converter support `text/xml`, `application/xml`, and `application/*-xml`. This can be overridden by setting the `supportedMediaTypes` property.

  Since:
    3.0
  Author:
    Arjen Poutsma

- - ### Field Summary

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

      `logger`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractXmlHttpMessageConverter()` Protected constructor that sets the `supportedMediaTypes` to `text/xml` and `application/xml`, and `application/*-xml`.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract T` | `readFromSource(Class<? extends T> clazz, HttpHeaders headers, Source source)` Abstract template method called from `AbstractHttpMessageConverter.read(Class, HttpInputMessage)`.
    `T` | `readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)` Abstract template method that reads the actual object.
    `protected void` | `transform(Source source, Result result)` Transforms the given `Source` to the `Result`.
    `protected void` | `writeInternal(T t, HttpOutputMessage outputMessage)` Abstract template method that writes the actual body.
    `protected abstract void` | `writeToResult(T t, HttpHeaders headers, Result result)` Abstract template method called from `writeInternal(Object, HttpOutputMessage)`.

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

      `canRead, canRead, canWrite, canWrite, getContentLength, getDefaultContentType, getSupportedMediaTypes, read, setSupportedMediaTypes, supports, write`

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

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

- - ### Constructor Detail

    - #### AbstractXmlHttpMessageConverter

          protected AbstractXmlHttpMessageConverter()

      Protected constructor that sets the `supportedMediaTypes` to `text/xml` and `application/xml`, and `application/*-xml`.

  - ### Method Detail

    - #### readInternal

          public final T readInternal(Class<? extends T> clazz,
                                      HttpInputMessage inputMessage)
                               throws IOException

      Description copied from class: `AbstractHttpMessageConverter`
      Abstract template method that reads the actual object. Invoked from `AbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)`.
      Specified by:
        `readInternal` in class `AbstractHttpMessageConverter<T>`
      Parameters:
        `clazz` - the type of object to return
        `inputMessage` - the HTTP input message to read from
      Returns:
        the converted object
      Throws:
        `IOException` - in case of I/O errors

    - #### writeInternal

          protected final void writeInternal(T t,
                                             HttpOutputMessage outputMessage)
                                      throws IOException

      Description copied from class: `AbstractHttpMessageConverter`
      Abstract template method that writes the actual body. Invoked from `AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)`.
      Specified by:
        `writeInternal` in class `AbstractHttpMessageConverter<T>`
      Parameters:
        `t` - the object to write to the output message
        `outputMessage` - the message to write to
      Throws:
        `IOException` - in case of I/O errors

    - #### transform

          protected void transform(Source source,
                                   Result result)
                            throws TransformerException

      Transforms the given `Source` to the `Result`.
      Parameters:
        `source` - the source to transform from
        `result` - the result to transform to
      Throws:
        `TransformerException` - in case of transformation errors

    - #### readFromSource

          protected abstract T readFromSource(Class<? extends T> clazz,
                                              HttpHeaders headers,
                                              Source source)
                                       throws IOException

      Abstract template method called from `AbstractHttpMessageConverter.read(Class, HttpInputMessage)`.
      Parameters:
        `clazz` - the type of object to return
        `headers` - the HTTP input headers
        `source` - the HTTP input body
      Returns:
        the converted object
      Throws:
        `IOException` - in case of I/O errors
        `HttpMessageConversionException` - in case of conversion errors

    - #### writeToResult

          protected abstract void writeToResult(T t,
                                                HttpHeaders headers,
                                                Result result)
                                         throws IOException

      Abstract template method called from `writeInternal(Object, HttpOutputMessage)`.
      Parameters:
        `t` - the object to write to the output message
        `headers` - the HTTP output headers
        `result` - the HTTP output body
      Throws:
        `IOException` - in case of I/O errors
        `HttpMessageConversionException` - in case of conversion errors