Skip to content

Commit 46c29b9

Browse files
committed
Support Boolean property in BindingReflectionHintsRegistrar
Closes gh-33380
1 parent 1634e63 commit 46c29b9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type
107107
registerPropertyHints(hints, seen, method, 0);
108108
}
109109
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) ||
110-
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
110+
(methodName.startsWith("is") && method.getParameterCount() == 0
111+
&& ClassUtils.resolvePrimitiveIfNecessary(method.getReturnType()) == Boolean.class)) {
111112
registerPropertyHints(hints, seen, method, -1);
112113
}
113114
}

spring-core/src/test/kotlin/org/springframework/aot/hint/BindingReflectionHintsRegistrarKotlinTests.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,8 +68,10 @@ class BindingReflectionHintsRegistrarKotlinTests {
6868
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "component1")).accepts(hints)
6969
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "copy")).accepts(hints)
7070
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "getName")).accepts(hints)
71+
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "isNonNullable")).accepts(hints)
72+
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "isNullable")).accepts(hints)
7173
val copyDefault: Method = SampleDataClass::class.java.getMethod("copy\$default", SampleDataClass::class.java,
72-
String::class.java , Int::class.java, Object::class.java)
74+
String::class.java, Boolean::class.javaPrimitiveType, Boolean::class.javaObjectType, Int::class.java, Object::class.java)
7375
assertThat(RuntimeHintsPredicates.reflection().onMethod(copyDefault)).accepts(hints)
7476
}
7577

@@ -84,6 +86,6 @@ class BindingReflectionHintsRegistrarKotlinTests {
8486
@kotlinx.serialization.Serializable
8587
class SampleSerializableClass(val name: String)
8688

87-
data class SampleDataClass(val name: String)
89+
data class SampleDataClass(val name: String, val isNonNullable: Boolean, val isNullable: Boolean?)
8890

8991
class SampleClass(val name: String)

0 commit comments

Comments
 (0)