Add support for Jackson annotations in BindingReflectionHintsRegistrar
This commits registers reflection hints on field and methods where Jackson annotations are detected. Closes gh-29426
This commit is contained in:
@@ -20,8 +20,10 @@ import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -219,6 +221,24 @@ public class BindingReflectionHintsRegistrarTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTypeForJacksonAnnotations() {
|
||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onField(SampleClassWithJsonProperty.class, "privateField"))
|
||||
.accepts(this.hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithJsonProperty.class, "packagePrivateMethod").invoke())
|
||||
.accepts(this.hints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTypeForInheritedJacksonAnnotations() {
|
||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithInheritedJsonProperty.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onField(SampleClassWithJsonProperty.class, "privateField"))
|
||||
.accepts(this.hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithJsonProperty.class, "packagePrivateMethod").invoke())
|
||||
.accepts(this.hints);
|
||||
}
|
||||
|
||||
|
||||
static class SampleEmptyClass {
|
||||
}
|
||||
@@ -291,7 +311,7 @@ public class BindingReflectionHintsRegistrarTests {
|
||||
}
|
||||
}
|
||||
|
||||
class SampleClassC {
|
||||
static class SampleClassC {
|
||||
public String getString() {
|
||||
return "";
|
||||
}
|
||||
@@ -303,4 +323,17 @@ public class BindingReflectionHintsRegistrarTests {
|
||||
|
||||
record SampleRecord(String name) {}
|
||||
|
||||
static class SampleClassWithJsonProperty {
|
||||
|
||||
@JsonProperty
|
||||
private String privateField = "";
|
||||
|
||||
@JsonProperty
|
||||
String packagePrivateMethod() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static class SampleClassWithInheritedJsonProperty extends SampleClassWithJsonProperty {}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user