Spring Framework

org.springframework.http.converter.xml
Class Jaxb2RootElementHttpMessageConverter

java.lang.Object
  extended by org.springframework.http.converter.AbstractHttpMessageConverter<T>
      extended by org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<T>
          extended by org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter<java.lang.Object>
              extended by org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<java.lang.Object>

public class Jaxb2RootElementHttpMessageConverter
extends AbstractJaxb2HttpMessageConverter<java.lang.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 with XmlRootElement, or subclasses thereof.

Since:
3.0
Author:
Arjen Poutsma

Field Summary
 
Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger
 
Constructor Summary
Jaxb2RootElementHttpMessageConverter()
           
 
Method Summary
 boolean canRead(java.lang.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(java.lang.Class<?> clazz, MediaType mediaType)
          This implementation checks if the given class is supported, and if the supported media types include the given media type.
protected  java.lang.Object readFromSource(java.lang.Class<?> clazz, HttpHeaders headers, javax.xml.transform.Source source)
          Abstract template method called from AbstractHttpMessageConverter.read(Class, HttpInputMessage).
protected  boolean supports(java.lang.Class<?> clazz)
          Indicates whether the given class is supported by this converter.
protected  void writeToResult(java.lang.Object o, HttpHeaders headers, javax.xml.transform.Result result)
          Abstract template method called from AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage).
 
Methods inherited from class org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter
createMarshaller, createUnmarshaller, getJaxbContext
 
Methods inherited from class org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter
readInternal, transform, writeInternal
 
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
canRead, canWrite, getContentLength, getDefaultContentType, getSupportedMediaTypes, read, setSupportedMediaTypes, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jaxb2RootElementHttpMessageConverter

public Jaxb2RootElementHttpMessageConverter()
Method Detail

canRead

public boolean canRead(java.lang.Class<?> clazz,
                       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<java.lang.Object>
Overrides:
canRead in class AbstractHttpMessageConverter<java.lang.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(java.lang.Class<?> clazz,
                        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<java.lang.Object>
Overrides:
canWrite in class AbstractHttpMessageConverter<java.lang.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(java.lang.Class<?> clazz)
Description copied from class: AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.

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

readFromSource

protected java.lang.Object readFromSource(java.lang.Class<?> clazz,
                                          HttpHeaders headers,
                                          javax.xml.transform.Source source)
                                   throws java.io.IOException
Description copied from class: AbstractXmlHttpMessageConverter
Abstract template method called from AbstractHttpMessageConverter.read(Class, HttpInputMessage).

Specified by:
readFromSource in class AbstractXmlHttpMessageConverter<java.lang.Object>
Parameters:
clazz - the type of object to return
headers - the HTTP input headers
source - the HTTP input body
Returns:
the converted object
Throws:
java.io.IOException - in case of I/O errors

writeToResult

protected void writeToResult(java.lang.Object o,
                             HttpHeaders headers,
                             javax.xml.transform.Result result)
                      throws java.io.IOException
Description copied from class: AbstractXmlHttpMessageConverter
Abstract template method called from AbstractXmlHttpMessageConverter.writeInternal(Object, HttpOutputMessage).

Specified by:
writeToResult in class AbstractXmlHttpMessageConverter<java.lang.Object>
Parameters:
o - the object to write to the output message
headers - the HTTP output headers
result - the HTTP output body
Throws:
java.io.IOException - in case of I/O errors

Spring Framework