Support properties on records in BindingReflectionHintsRegistrar
Closes gh-29571
This commit is contained in:
@@ -91,19 +91,17 @@ public class BindingReflectionHintsRegistrar {
|
||||
registerRecordHints(hints, seen, recordComponent.getAccessor());
|
||||
}
|
||||
}
|
||||
else {
|
||||
typeHint.withMembers(
|
||||
MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
for (Method method : clazz.getMethods()) {
|
||||
String methodName = method.getName();
|
||||
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
|
||||
registerPropertyHints(hints, seen, method, 0);
|
||||
}
|
||||
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
|
||||
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
|
||||
registerPropertyHints(hints, seen, method, -1);
|
||||
}
|
||||
typeHint.withMembers(
|
||||
MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
for (Method method : clazz.getMethods()) {
|
||||
String methodName = method.getName();
|
||||
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
|
||||
registerPropertyHints(hints, seen, method, 0);
|
||||
}
|
||||
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
|
||||
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
|
||||
registerPropertyHints(hints, seen, method, -1);
|
||||
}
|
||||
}
|
||||
if (jacksonAnnotationPresent) {
|
||||
|
||||
@@ -221,6 +221,13 @@ public class BindingReflectionHintsRegistrarTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTypeForSerializationWithRecordWithProperty() {
|
||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleRecordWithProperty.class);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleRecordWithProperty.class, "getNameProperty"))
|
||||
.accepts(this.hints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTypeForSerializationWithAnonymousClass() {
|
||||
Runnable anonymousRunnable = () -> { };
|
||||
@@ -329,6 +336,13 @@ public class BindingReflectionHintsRegistrarTests {
|
||||
|
||||
record SampleRecord(String name) {}
|
||||
|
||||
record SampleRecordWithProperty(String name) {
|
||||
|
||||
public String getNameProperty() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static class SampleClassWithJsonProperty {
|
||||
|
||||
@JsonProperty
|
||||
|
||||
Reference in New Issue
Block a user