Add dynamic ObjectToObjectConverter hints

This commit refines BindingReflectionHintsRegistrar with additional
dynamic hints for application-defined types, main core Java conversion
ones being already covered by ObjectToObjectConverterRuntimeHints.

Closes gh-35847
This commit is contained in:
Sébastien Deleuze
2025-11-26 16:17:41 +01:00
parent 6504177e7b
commit 8647c44364
3 changed files with 61 additions and 0 deletions
@@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import org.junit.jupiter.api.Test;
import org.springframework.aot.hint.predicate.ReflectionHintsPredicates;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.core.ResolvableType;
@@ -301,6 +302,16 @@ class BindingReflectionHintsRegistrarTests {
.accepts(this.hints);
}
@Test
void registerTypeForObjectToObjectConverter() {
bindingRegistrar.registerReflectionHints(this.hints.reflection(), Source.class);
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
assertThat(reflection.onMethodInvocation(Source.class, "valueOf")).accepts(this.hints);
assertThat(reflection.onMethodInvocation(Source.class, "of")).accepts(this.hints);
assertThat(reflection.onMethodInvocation(Source.class, "from")).accepts(this.hints);
assertThat(reflection.onMethodInvocation(Source.class, "toData")).accepts(this.hints);
}
static class SampleEmptyClass {
}
@@ -460,4 +471,31 @@ class BindingReflectionHintsRegistrarTests {
}
}
static class Source {
private final String value;
private Source(String value) {
this.value = value;
}
public static Source valueOf(String value) {
return new Source(value);
}
public static Source of(String value) {
return new Source(value);
}
public static Source from(String value) {
return new Source(value);
}
public Data toData() {
return new Data(this.value);
}
}
record Data(String value) { }
}