Improve `@RegisterReflectionForBinding` for enums

Closes gh-31570
This commit is contained in:
Sébastien Deleuze 2023-12-05 16:53:42 +01:00
parent c74d60b9fe
commit 3f9a809c32
2 changed files with 7 additions and 2 deletions

View File

@ -94,6 +94,11 @@ public class BindingReflectionHintsRegistrar {
registerRecordHints(hints, seen, recordComponent.getAccessor());
}
}
if (clazz.isEnum()) {
typeHint.withMembers(
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_METHODS);
}
typeHint.withMembers(
MemberCategory.DECLARED_FIELDS,
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);

View File

@ -229,8 +229,8 @@ class BindingReflectionHintsRegistrarTests {
@Test
void registerTypeForSerializationWithEnum() {
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleEnum.class);
assertThat(this.hints.reflection().typeHints()).singleElement()
.satisfies(typeHint -> assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleEnum.class)));
assertThat(RuntimeHintsPredicates.reflection().onType(SampleEnum.class).withMemberCategories(
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(this.hints);
}
@Test