Package org.springframework.http.converter.xml

# Class AbstractJaxb2HttpMessageConverter<T>

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

Type Parameters:
  `T` - the converted object type

All Implemented Interfaces:
  `HttpMessageConverter<T>`

Direct Known Subclasses:
  `Jaxb2CollectionHttpMessageConverter`, `Jaxb2RootElementHttpMessageConverter`

public abstract class AbstractJaxb2HttpMessageConverter<T> extends AbstractXmlHttpMessageConverter<T>
Abstract base class for `HttpMessageConverters` that use JAXB2. Creates `JAXBContext` object lazily.

Since:
  3.0
Author:
  Arjen Poutsma, Rossen Stoyanchev

## Field Summary

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

`logger`

## Constructor Summary

Constructors
Constructor
Description
`AbstractJaxb2HttpMessageConverter()`

## Method Summary

Modifier and Type
Method
Description
`protected final Marshaller`
`createMarshaller(Class<?> clazz)`
Create a new `Marshaller` for the given class.
`protected final Unmarshaller`
`createUnmarshaller(Class<?> clazz)`
Create a new `Unmarshaller` for the given class.
`protected void`
`customizeMarshaller(Marshaller marshaller)`
Customize the `Marshaller` created by this message converter before using it to write the object to the output.
`protected void`
`customizeUnmarshaller(Unmarshaller unmarshaller)`
Customize the `Unmarshaller` created by this message converter before using it to read the object from the input.
`protected Charset`
`detectCharset(HttpHeaders httpHeaders)`
Detect the charset from the given `HttpHeaders.getContentType()`.
`protected final JAXBContext`
`getJaxbContext(Class<?> clazz)`
Return a `JAXBContext` for the given class.

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

`readFromSource, readInternal, transform, writeInternal, writeToResult`

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

`addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, supports, supportsRepeatableWrites, 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

### AbstractJaxb2HttpMessageConverter

public AbstractJaxb2HttpMessageConverter()

## Method Details

### createMarshaller

protected final Marshaller createMarshaller(Class<?> clazz)
Create a new `Marshaller` for the given class.

Parameters:
  `clazz` - the class to create the marshaller for
Returns:
  the `Marshaller`
Throws:
  `HttpMessageConversionException` - in case of JAXB errors

### customizeMarshaller

protected void customizeMarshaller(Marshaller marshaller)
Customize the `Marshaller` created by this message converter before using it to write the object to the output.

Parameters:
  `marshaller` - the marshaller to customize
Since:
  4.0.3
See Also:
  - `createMarshaller(Class)`

### createUnmarshaller

protected final Unmarshaller createUnmarshaller(Class<?> clazz)
Create a new `Unmarshaller` for the given class.

Parameters:
  `clazz` - the class to create the unmarshaller for
Returns:
  the `Unmarshaller`
Throws:
  `HttpMessageConversionException` - in case of JAXB errors

### customizeUnmarshaller

protected void customizeUnmarshaller(Unmarshaller unmarshaller)
Customize the `Unmarshaller` created by this message converter before using it to read the object from the input.

Parameters:
  `unmarshaller` - the unmarshaller to customize
Since:
  4.0.3
See Also:
  - `createUnmarshaller(Class)`

### getJaxbContext

protected final JAXBContext getJaxbContext(Class<?> clazz)
Return a `JAXBContext` for the given class.

Parameters:
  `clazz` - the class to return the context for
Returns:
  the `JAXBContext`
Throws:
  `HttpMessageConversionException` - in case of JAXB errors

### detectCharset

@Nullable protected Charset detectCharset(HttpHeaders httpHeaders)
Detect the charset from the given `HttpHeaders.getContentType()`.

Parameters:
  `httpHeaders` - the current HTTP headers
Returns:
  the charset defined in the content type header, or `null` if not found
Since:
  6.2.8