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>
This commit is contained in:
Maurice Zeijen
2025-11-24 09:57:43 +01:00
committed by Brian Clozel
parent 0a4037880c
commit a39adff3eb
2 changed files with 3 additions and 2 deletions
@@ -66,6 +66,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.core.Ordered;
import org.springframework.http.ProblemDetail;
import org.springframework.http.converter.json.ProblemDetailJacksonMixin;
import org.springframework.http.converter.json.ProblemDetailJacksonXmlMixin;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -282,7 +283,7 @@ public final class JacksonAutoConfiguration {
@Override
public void customize(XmlMapper.Builder builder) {
builder.addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class);
builder.addMixIn(ProblemDetail.class, ProblemDetailJacksonXmlMixin.class);
}
}
@@ -691,7 +691,7 @@ class JacksonAutoConfigurationTests {
problemDetail.setProperty("spring", "boot");
String xml = mapper.writeValueAsString(problemDetail);
assertThat(xml).isEqualTo(
"<ProblemDetail><status>404</status><title>Not Found</title><spring>boot</spring></ProblemDetail>");
"<problem xmlns=\"urn:ietf:rfc:7807\"><status>404</status><title>Not Found</title><spring>boot</spring></problem>");
});
}