Skip to content

Commit 1c217aa

Browse files
committed
Support text/xml and application/*+xml in Jackson XML message converter
Issue: SPR-12366
1 parent 49f3a6b commit 1c217aa

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*
3030
* <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
3131
*
32-
* <p>By default, this converter supports {@code application/json}. This can be overridden by setting the
33-
* {@link #setSupportedMediaTypes supportedMediaTypes} property.
32+
* <p>By default, this converter supports {@code application/json} and {@code application/*+json}.
33+
* This can be overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property.
3434
*
3535
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
3636
*

spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
* that can read and write XML using <a href="https://github.com/FasterXML/jackson-dataformat-xml">
3030
* Jackson 2.x extension component for reading and writing XML encoded data</a>.
3131
*
32+
* <p>By default, this converter supports {@code application/xml}, {@code text/xml}, and {@code application/*+xml}.
33+
* This can be overridden by setting the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes} property.
34+
*
3235
* <p>The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}.
3336
*
37+
* <p>Compatible with Jackson 2.1 and higher.
38+
*
3439
* @author Sebastien Deleuze
3540
* @since 4.1
3641
*/
@@ -51,7 +56,9 @@ public MappingJackson2XmlHttpMessageConverter() {
5156
* @see Jackson2ObjectMapperBuilder#xml()
5257
*/
5358
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
54-
super(objectMapper, new MediaType("application", "xml", DEFAULT_CHARSET));
59+
super(objectMapper, new MediaType("application", "xml", DEFAULT_CHARSET),
60+
new MediaType("text", "xml", DEFAULT_CHARSET),
61+
new MediaType("application", "*+xml", DEFAULT_CHARSET));
5562
Assert.isAssignable(XmlMapper.class, objectMapper.getClass());
5663
}
5764

spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ public class MappingJackson2XmlHttpMessageConverterTests {
4949
@Test
5050
public void canRead() {
5151
assertTrue(converter.canRead(MyBean.class, new MediaType("application", "xml")));
52+
assertTrue(converter.canRead(MyBean.class, new MediaType("text", "xml")));
53+
assertTrue(converter.canRead(MyBean.class, new MediaType("application", "soap+xml")));
5254
}
5355

5456
@Test
5557
public void canWrite() {
5658
assertTrue(converter.canWrite(MyBean.class, new MediaType("application", "xml")));
59+
assertTrue(converter.canWrite(MyBean.class, new MediaType("text", "xml")));
60+
assertTrue(converter.canWrite(MyBean.class, new MediaType("application", "soap+xml")));
5761
}
5862

5963
@Test

0 commit comments

Comments
 (0)