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());
|
registerRecordHints(hints, seen, recordComponent.getAccessor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
typeHint.withMembers(
|
||||||
typeHint.withMembers(
|
MemberCategory.DECLARED_FIELDS,
|
||||||
MemberCategory.DECLARED_FIELDS,
|
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
for (Method method : clazz.getMethods()) {
|
||||||
for (Method method : clazz.getMethods()) {
|
String methodName = method.getName();
|
||||||
String methodName = method.getName();
|
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
|
||||||
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
|
registerPropertyHints(hints, seen, method, 0);
|
||||||
registerPropertyHints(hints, seen, method, 0);
|
}
|
||||||
}
|
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
|
||||||
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
|
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
|
||||||
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
|
registerPropertyHints(hints, seen, method, -1);
|
||||||
registerPropertyHints(hints, seen, method, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jacksonAnnotationPresent) {
|
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
|
@Test
|
||||||
void registerTypeForSerializationWithAnonymousClass() {
|
void registerTypeForSerializationWithAnonymousClass() {
|
||||||
Runnable anonymousRunnable = () -> { };
|
Runnable anonymousRunnable = () -> { };
|
||||||
@@ -329,6 +336,13 @@ public class BindingReflectionHintsRegistrarTests {
|
|||||||
|
|
||||||
record SampleRecord(String name) {}
|
record SampleRecord(String name) {}
|
||||||
|
|
||||||
|
record SampleRecordWithProperty(String name) {
|
||||||
|
|
||||||
|
public String getNameProperty() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class SampleClassWithJsonProperty {
|
static class SampleClassWithJsonProperty {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
|||||||
Reference in New Issue
Block a user