mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 00:09:02 +00:00
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:
+38
@@ -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) { }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user