Skip to content

Commit

Permalink
Register hints for superclass in BindingReflectionHintsRegistrar
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Nov 9, 2023
1 parent 1e78cc3 commit 620f558
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ private void collectReferencedTypes(Set<Class<?>> types, ResolvableType resolvab
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ void registerTypeForSerializationWithEmptyClass() {
});
}

@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);
Expand Down Expand Up @@ -284,6 +306,9 @@ void registerTypeForAnnotationOnMethodAndField() {
static class SampleEmptyClass {
}

static class SampleExtendingClass extends SampleEmptyClass {
}

static class SampleClassWithNoProperty {

String name() {
Expand Down

0 comments on commit 620f558

Please sign in to comment.