Skip to content

Commit 6d4c009

Browse files
committed
Add application/*+xml to Jaxb2XmlEncoder
Closes gh-26655
1 parent 55aa8e9 commit 6d4c009

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import org.springframework.core.io.buffer.DataBufferFactory;
4040
import org.springframework.core.io.buffer.DataBufferUtils;
4141
import org.springframework.core.log.LogFormatUtils;
42+
import org.springframework.http.MediaType;
4243
import org.springframework.lang.Nullable;
4344
import org.springframework.util.ClassUtils;
4445
import org.springframework.util.MimeType;
@@ -64,7 +65,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
6465

6566

6667
public Jaxb2XmlEncoder() {
67-
super(MimeTypeUtils.APPLICATION_XML, MimeTypeUtils.TEXT_XML);
68+
super(MimeTypeUtils.APPLICATION_XML, MimeTypeUtils.TEXT_XML, new MediaType("application", "*+xml"));
6869
}
6970

7071

spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlEncoderTests.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737

3838
import static java.nio.charset.StandardCharsets.UTF_8;
3939
import static org.assertj.core.api.Assertions.assertThat;
40+
import static org.springframework.core.ResolvableType.forClass;
4041
import static org.springframework.core.io.buffer.DataBufferUtils.release;
4142

4243
/**
@@ -52,19 +53,13 @@ public Jaxb2XmlEncoderTests() {
5253
@Override
5354
@Test
5455
public void canEncode() {
55-
assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
56-
MediaType.APPLICATION_XML)).isTrue();
57-
assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
58-
MediaType.TEXT_XML)).isTrue();
59-
assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
60-
MediaType.APPLICATION_JSON)).isFalse();
61-
62-
assertThat(this.encoder.canEncode(
63-
ResolvableType.forClass(Jaxb2XmlDecoderTests.TypePojo.class),
64-
MediaType.APPLICATION_XML)).isTrue();
65-
66-
assertThat(this.encoder.canEncode(ResolvableType.forClass(getClass()),
67-
MediaType.APPLICATION_XML)).isFalse();
56+
assertThat(this.encoder.canEncode(forClass(Pojo.class), MediaType.APPLICATION_XML)).isTrue();
57+
assertThat(this.encoder.canEncode(forClass(Pojo.class), MediaType.TEXT_XML)).isTrue();
58+
assertThat(this.encoder.canEncode(forClass(Pojo.class), new MediaType("application", "foo+xml"))).isTrue();
59+
assertThat(this.encoder.canEncode(forClass(Pojo.class), MediaType.APPLICATION_JSON)).isFalse();
60+
61+
assertThat(this.encoder.canEncode(forClass(Jaxb2XmlDecoderTests.TypePojo.class), MediaType.APPLICATION_XML)).isTrue();
62+
assertThat(this.encoder.canEncode(forClass(getClass()), MediaType.APPLICATION_XML)).isFalse();
6863

6964
// SPR-15464
7065
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isFalse();

0 commit comments

Comments
 (0)