Browse Source

Merge branch '6.0.x'

pull/31531/merge
Stéphane Nicoll 1 year ago
parent
commit
f15b8b95ad
  1. 8
      spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java
  2. 17
      spring-web/src/test/java/org/springframework/http/converter/json/ProblemDetailRuntimeHintsTests.java

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

@ -20,12 +20,14 @@ import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.http.ProblemDetail; import org.springframework.http.ProblemDetail;
import org.springframework.util.ClassUtils;
/** /**
* {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries * {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries
* for {@link ProblemDetail} serialization support with Jackson. * for {@link ProblemDetail} serialization support with Jackson.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Stephane Nicoll
* @since 6.0.5 * @since 6.0.5
*/ */
class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar { class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
@ -34,6 +36,12 @@ class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar(); BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetail.class); bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetail.class);
if (ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader)) {
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetailJacksonXmlMixin.class);
}
else if (ClassUtils.isPresent("com.fasterxml.jackson.annotation.JacksonAnnotation", classLoader)) {
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetailJacksonMixin.class);
}
} }
} }

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

@ -37,6 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class ProblemDetailRuntimeHintsTests { class ProblemDetailRuntimeHintsTests {
private static final List<String> METHOD_NAMES = List.of("getType", "getTitle",
"getStatus", "getDetail", "getInstance", "getProperties");
private final RuntimeHints hints = new RuntimeHints(); private final RuntimeHints hints = new RuntimeHints();
@BeforeEach @BeforeEach
@ -48,9 +51,17 @@ class ProblemDetailRuntimeHintsTests {
@Test @Test
void getterMethodsShouldHaveReflectionHints() { void getterMethodsShouldHaveReflectionHints() {
List<String> methodNames = List.of("getType", "getTitle", "getStatus", "getDetail", "getInstance", "getProperties"); for (String methodName : METHOD_NAMES) {
for (String methodName : methodNames) { assertThat(RuntimeHintsPredicates.reflection()
assertThat(RuntimeHintsPredicates.reflection().onMethod(ProblemDetail.class, methodName)).accepts(this.hints); .onMethod(ProblemDetail.class, methodName)).accepts(this.hints);
}
}
@Test
void mixinShouldHaveReflectionHints() {
for (String methodName : METHOD_NAMES) {
assertThat(RuntimeHintsPredicates.reflection()
.onMethod(ProblemDetailJacksonXmlMixin.class, methodName)).accepts(this.hints);
} }
} }

Loading…
Cancel
Save