Skip to content

Commit 295d14e

Browse files
committed
Backoff KotlinBeanInfoFactory for enum types.
We now no longer contribute properties for enum types. Closes #2990
1 parent 197e4cc commit 295d14e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered {
4848
@Override
4949
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
5050

51-
if (beanClass.isInterface()) {
51+
if (beanClass.isInterface() || beanClass.isEnum()) {
5252
return null; // back-off to leave interface-based properties to the default mechanism.
5353
}
5454

5555
if (!KotlinDetector.isKotlinReflectPresent() || !KotlinDetector.isKotlinType(beanClass)) {
5656
return null;
5757
}
5858

59-
6059
KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(beanClass);
6160
List<PropertyDescriptor> pds = new ArrayList<>();
6261

src/test/kotlin/org/springframework/data/util/KotlinBeanInfoFactoryUnitTests.kt

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class KotlinBeanInfoFactoryUnitTests {
7373
assertThat(pds).hasSize(1).extracting("name").containsOnly("firstname")
7474
}
7575

76+
@Test // GH-2990
77+
internal fun backsOffForEnums() {
78+
79+
val pds = BeanUtils.getPropertyDescriptors(MyEnum::class.java)
80+
81+
assertThat(pds).extracting("name").contains("ordinal")
82+
}
83+
7684
data class SimpleDataClass(val id: String, var name: String)
7785

7886
@JvmInline
@@ -86,4 +94,8 @@ class KotlinBeanInfoFactoryUnitTests {
8694
fun getFirstname(): String
8795
}
8896

97+
enum class MyEnum {
98+
Foo, Bar
99+
}
100+
89101
}

0 commit comments

Comments
 (0)