public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2HttpMessageConverter
HttpMessageConverter
that can read and write XML using
Jackson 2.x extension component for reading and writing XML encoded data.
By default, this converter supports application/xml
, text/xml
, and
application/*+xml
with UTF-8
character set. This can be overridden by
setting the supportedMediaTypes
property.
The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder
.
Compatible with Jackson 2.9 and higher, as of Spring 5.0.
DEFAULT_CHARSET, objectMapper
logger
Constructor and Description |
---|
MappingJackson2XmlHttpMessageConverter()
Construct a new
MappingJackson2XmlHttpMessageConverter using default configuration
provided by Jackson2ObjectMapperBuilder . |
MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper)
Construct a new
MappingJackson2XmlHttpMessageConverter with a custom ObjectMapper
(must be a XmlMapper instance). |
Modifier and Type | Method and Description |
---|---|
void |
setObjectMapper(ObjectMapper objectMapper)
Set the
ObjectMapper for this view. |
canRead, canRead, canWrite, getCharset, getContentLength, getDefaultContentType, getJavaType, getJsonEncoding, getObjectMapper, logWarningIfNecessary, read, readInternal, setPrettyPrint, writeInternal, writePrefix, writeSuffix
canWrite, supports, write, writeInternal
addDefaultHeaders, canRead, canWrite, getDefaultCharset, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSupportedMediaTypes, read, write
public MappingJackson2XmlHttpMessageConverter()
MappingJackson2XmlHttpMessageConverter
using default configuration
provided by Jackson2ObjectMapperBuilder
.public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper)
MappingJackson2XmlHttpMessageConverter
with a custom ObjectMapper
(must be a XmlMapper
instance).
You can use Jackson2ObjectMapperBuilder
to build it easily.Jackson2ObjectMapperBuilder.xml()
public void setObjectMapper(ObjectMapper objectMapper)
ObjectMapper
for this view.
If not set, a default ObjectMapper
is used.
Setting a custom-configured ObjectMapper
is one way to take further
control of the JSON serialization process. For example, an extended
SerializerFactory
can be configured that provides custom serializers for specific types.
The other option for refining the serialization process is to use Jackson's
provided annotations on the types to be serialized, in which case a
custom-configured ObjectMapper is unnecessary.
The ObjectMapper
parameter must be a XmlMapper
instance.
setObjectMapper
in class AbstractJackson2HttpMessageConverter