Browse Source

Merge branch '6.0.x'

pull/30534/merge
Sébastien Deleuze 1 year ago
parent
commit
d8ed7c7906
  1. 4
      spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java
  2. 25
      spring-core/src/test/java/org/springframework/aot/hint/BindingReflectionHintsRegistrarTests.java

4
spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

@ -159,6 +159,10 @@ public class BindingReflectionHintsRegistrar { @@ -159,6 +159,10 @@ public class BindingReflectionHintsRegistrar {
for (ResolvableType genericResolvableType : resolvableType.getGenerics()) {
collectReferencedTypes(types, genericResolvableType);
}
Class<?> superClass = clazz.getSuperclass();
if (superClass != null && superClass != Object.class && superClass != Record.class && superClass != Enum.class) {
types.add(superClass);
}
}
}

25
spring-core/src/test/java/org/springframework/aot/hint/BindingReflectionHintsRegistrarTests.java

@ -63,6 +63,28 @@ class BindingReflectionHintsRegistrarTests { @@ -63,6 +63,28 @@ class BindingReflectionHintsRegistrarTests {
});
}
@Test
void registerTypeForSerializationWithExtendingClass() {
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleExtendingClass.class);
assertThat(this.hints.reflection().typeHints()).satisfiesExactlyInAnyOrder(
typeHint -> {
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleEmptyClass.class));
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
assertThat(typeHint.constructors()).isEmpty();
assertThat(typeHint.fields()).isEmpty();
assertThat(typeHint.methods()).isEmpty();
},
typeHint -> {
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleExtendingClass.class));
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
assertThat(typeHint.constructors()).isEmpty();
assertThat(typeHint.fields()).isEmpty();
assertThat(typeHint.methods()).isEmpty();
});
}
@Test
void registerTypeForSerializationWithNoProperty() {
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithNoProperty.class);
@ -284,6 +306,9 @@ class BindingReflectionHintsRegistrarTests { @@ -284,6 +306,9 @@ class BindingReflectionHintsRegistrarTests {
static class SampleEmptyClass {
}
static class SampleExtendingClass extends SampleEmptyClass {
}
static class SampleClassWithNoProperty {
String name() {

Loading…
Cancel
Save