Skip to content

Commit a39adff

Browse files
mzeijenbclozel
authored andcommitted
Corrected ProblemDetail mixin for XmlMapper.Builder
The ProblemDetailXmlMapperBuilderCustomizer applied the wrong ProblemDetail mixin for the Jackson XmlMapper. Namely the ProblemDetailJacksonMixin, which is intended for JSON. Now the ProblemDetailJacksonXmlMixin is used instead. The corresponding test also tested for the wrong XML output, which has been adjusted. Fixes gh-48222 Signed-off-by: Maurice Zeijen <mzeijen@bol.com>
1 parent 0a40378 commit a39adff

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.springframework.core.Ordered;
6767
import org.springframework.http.ProblemDetail;
6868
import org.springframework.http.converter.json.ProblemDetailJacksonMixin;
69+
import org.springframework.http.converter.json.ProblemDetailJacksonXmlMixin;
6970
import org.springframework.util.Assert;
7071
import org.springframework.util.ClassUtils;
7172
import org.springframework.util.ReflectionUtils;
@@ -282,7 +283,7 @@ static final class ProblemDetailXmlMapperBuilderCustomizer implements XmlMapperB
282283

283284
@Override
284285
public void customize(XmlMapper.Builder builder) {
285-
builder.addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class);
286+
builder.addMixIn(ProblemDetail.class, ProblemDetailJacksonXmlMixin.class);
286287
}
287288

288289
}

module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void shouldRegisterProblemDetailsMixinWithXmlMapper() {
691691
problemDetail.setProperty("spring", "boot");
692692
String xml = mapper.writeValueAsString(problemDetail);
693693
assertThat(xml).isEqualTo(
694-
"<ProblemDetail><status>404</status><title>Not Found</title><spring>boot</spring></ProblemDetail>");
694+
"<problem xmlns=\"urn:ietf:rfc:7807\"><status>404</status><title>Not Found</title><spring>boot</spring></problem>");
695695
});
696696
}
697697

0 commit comments

Comments
 (0)