Skip to content

Commit

Permalink
Add missing runtime hints for ProblemDetail mixins
Browse files Browse the repository at this point in the history
Closes gh-31606
  • Loading branch information
snicoll committed Nov 15, 2023
1 parent 8868fe2 commit 4464251
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.http.ProblemDetail;
import org.springframework.util.ClassUtils;

/**
* {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries
* for {@link ProblemDetail} serialization support with Jackson.
*
* @author Brian Clozel
* @author Stephane Nicoll
* @since 6.0.5
*/
class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
Expand All @@ -34,6 +36,12 @@ class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
*/
class ProblemDetailRuntimeHintsTests {

private static final List<String> METHOD_NAMES = List.of("getType", "getTitle",
"getStatus", "getDetail", "getInstance", "getProperties");

private final RuntimeHints hints = new RuntimeHints();

@BeforeEach
Expand All @@ -48,9 +51,17 @@ void setup() {

@Test
void getterMethodsShouldHaveReflectionHints() {
List<String> methodNames = List.of("getType", "getTitle", "getStatus", "getDetail", "getInstance", "getProperties");
for (String methodName : methodNames) {
assertThat(RuntimeHintsPredicates.reflection().onMethod(ProblemDetail.class, methodName)).accepts(this.hints);
for (String methodName : METHOD_NAMES) {
assertThat(RuntimeHintsPredicates.reflection()
.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);
}
}

Expand Down

0 comments on commit 4464251

Please sign in to comment.