diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java index 524ae5e9f9..c086c2c7ec 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.List; import org.springframework.aot.hint.ExecutableMode; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; @@ -37,15 +39,17 @@ class ObjectToObjectConverterRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + ReflectionHints reflectionHints = hints.reflection(); TypeReference sqlDateTypeReference = TypeReference.of("java.sql.Date"); - hints.reflection().registerTypeIfPresent(classLoader, sqlDateTypeReference.getName(), hint -> hint + reflectionHints.registerTypeIfPresent(classLoader, sqlDateTypeReference.getName(), hint -> hint .withMethod("toLocalDate", Collections.emptyList(), ExecutableMode.INVOKE) .onReachableType(sqlDateTypeReference) .withMethod("valueOf", List.of(TypeReference.of(LocalDate.class)), ExecutableMode.INVOKE) .onReachableType(sqlDateTypeReference)); - hints.reflection().registerTypeIfPresent(classLoader, "org.springframework.http.HttpMethod", + reflectionHints.registerTypeIfPresent(classLoader, "org.springframework.http.HttpMethod", builder -> builder.withMethod("valueOf", List.of(TypeReference.of(String.class)), ExecutableMode.INVOKE)); + reflectionHints.registerTypeIfPresent(classLoader, "java.net.URI", MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-core/src/test/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHintsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHintsTests.java index 6cea9b055b..1e8384b9e0 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHintsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHintsTests.java @@ -16,6 +16,7 @@ package org.springframework.aot.hint.support; +import java.net.URI; import java.time.LocalDate; import org.junit.jupiter.api.BeforeEach; @@ -52,4 +53,9 @@ class ObjectToObjectConverterRuntimeHintsTests { assertThat(RuntimeHintsPredicates.reflection().onMethod(java.sql.Date.class.getMethod("valueOf", LocalDate.class))).accepts(this.hints); } + @Test + void uriHasHints() throws NoSuchMethodException { + assertThat(RuntimeHintsPredicates.reflection().onConstructor(URI.class.getConstructor(String.class))).accepts(this.hints); + } + }