Skip to content

Commit f15b8b9

Browse files
committed
Merge branch '6.0.x'
2 parents 183c2f8 + 4464251 commit f15b8b9

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import org.springframework.aot.hint.RuntimeHints;
2121
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2222
import org.springframework.http.ProblemDetail;
23+
import org.springframework.util.ClassUtils;
2324

2425
/**
2526
* {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries
2627
* for {@link ProblemDetail} serialization support with Jackson.
2728
*
2829
* @author Brian Clozel
30+
* @author Stephane Nicoll
2931
* @since 6.0.5
3032
*/
3133
class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
@@ -34,6 +36,12 @@ class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
3436
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
3537
BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
3638
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetail.class);
39+
if (ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader)) {
40+
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetailJacksonXmlMixin.class);
41+
}
42+
else if (ClassUtils.isPresent("com.fasterxml.jackson.annotation.JacksonAnnotation", classLoader)) {
43+
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetailJacksonMixin.class);
44+
}
3745
}
3846

3947
}

spring-web/src/test/java/org/springframework/http/converter/json/ProblemDetailRuntimeHintsTests.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
*/
3838
class ProblemDetailRuntimeHintsTests {
3939

40+
private static final List<String> METHOD_NAMES = List.of("getType", "getTitle",
41+
"getStatus", "getDetail", "getInstance", "getProperties");
42+
4043
private final RuntimeHints hints = new RuntimeHints();
4144

4245
@BeforeEach
@@ -48,9 +51,17 @@ void setup() {
4851

4952
@Test
5053
void getterMethodsShouldHaveReflectionHints() {
51-
List<String> methodNames = List.of("getType", "getTitle", "getStatus", "getDetail", "getInstance", "getProperties");
52-
for (String methodName : methodNames) {
53-
assertThat(RuntimeHintsPredicates.reflection().onMethod(ProblemDetail.class, methodName)).accepts(this.hints);
54+
for (String methodName : METHOD_NAMES) {
55+
assertThat(RuntimeHintsPredicates.reflection()
56+
.onMethod(ProblemDetail.class, methodName)).accepts(this.hints);
57+
}
58+
}
59+
60+
@Test
61+
void mixinShouldHaveReflectionHints() {
62+
for (String methodName : METHOD_NAMES) {
63+
assertThat(RuntimeHintsPredicates.reflection()
64+
.onMethod(ProblemDetailJacksonXmlMixin.class, methodName)).accepts(this.hints);
5465
}
5566
}
5667

0 commit comments

Comments
 (0)