Skip to content

Commit

Permalink
Support text/xml and application/*+xml in Jackson XML message converter
Browse files Browse the repository at this point in the history
Issue: SPR-12366
  • Loading branch information
sdeleuze committed Oct 23, 2014
1 parent 49f3a6b commit 1c217aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*
* <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
*
* <p>By default, this converter supports {@code application/json}. This can be overridden by setting the
* {@link #setSupportedMediaTypes supportedMediaTypes} property.
* <p>By default, this converter supports {@code application/json} and {@code application/*+json}.
* This can be overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
*
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
* that can read and write XML using <a href="https://github.com/FasterXML/jackson-dataformat-xml">
* Jackson 2.x extension component for reading and writing XML encoded data</a>.
*
* <p>By default, this converter supports {@code application/xml}, {@code text/xml}, and {@code application/*+xml}.
* This can be overridden by setting the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes} property.
*
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
*
* <p>Compatible with Jackson 2.1 and higher.
*
* @author Sebastien Deleuze
* @since 4.1
*/
Expand All @@ -51,7 +56,9 @@ public MappingJackson2XmlHttpMessageConverter() {
* @see Jackson2ObjectMapperBuilder#xml()
*/
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, new MediaType("application", "xml", DEFAULT_CHARSET));
super(objectMapper, new MediaType("application", "xml", DEFAULT_CHARSET),
new MediaType("text", "xml", DEFAULT_CHARSET),
new MediaType("application", "*+xml", DEFAULT_CHARSET));
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ public class MappingJackson2XmlHttpMessageConverterTests {
@Test
public void canRead() {
assertTrue(converter.canRead(MyBean.class, new MediaType("application", "xml")));
assertTrue(converter.canRead(MyBean.class, new MediaType("text", "xml")));
assertTrue(converter.canRead(MyBean.class, new MediaType("application", "soap+xml")));
}

@Test
public void canWrite() {
assertTrue(converter.canWrite(MyBean.class, new MediaType("application", "xml")));
assertTrue(converter.canWrite(MyBean.class, new MediaType("text", "xml")));
assertTrue(converter.canWrite(MyBean.class, new MediaType("application", "soap+xml")));
}

@Test
Expand Down

0 comments on commit 1c217aa

Please sign in to comment.