Skip to content

Commit

Permalink
Add missing hint for converting String to URI
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze authored and mdeinum committed Jun 29, 2023
1 parent 38a4dfc commit dca4e20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -21,6 +21,8 @@
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;
Expand All @@ -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);
}

}
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aot.hint.support;

import java.net.URI;
import java.time.LocalDate;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -52,4 +53,9 @@ void javaSqlDateHasHints() throws NoSuchMethodException {
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);
}

}

0 comments on commit dca4e20

Please sign in to comment.