Register hints for superclass in BindingReflectionHintsRegistrar
Closes gh-31552
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
static class SampleEmptyClass {
|
||||
}
|
||||
|
||||
static class SampleExtendingClass extends SampleEmptyClass {
|
||||
}
|
||||
|
||||
static class SampleClassWithNoProperty {
|
||||
|
||||
String name() {
|
||||
|
||||
Reference in New Issue
Block a user