Browse Source

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>
pull/48276/head
Maurice Zeijen 4 weeks ago committed by Brian Clozel
parent
commit
a39adff3eb
  1. 3
      module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfiguration.java
  2. 2
      module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java

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

@ -66,6 +66,7 @@ import org.springframework.context.annotation.Scope; @@ -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 { @@ -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);
}
}

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

@ -691,7 +691,7 @@ class JacksonAutoConfigurationTests { @@ -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>");
});
}

Loading…
Cancel
Save