Skip to content

Commit

Permalink
Backoff KotlinBeanInfoFactory for enum types.
Browse files Browse the repository at this point in the history
We now no longer contribute properties for enum types.

Closes #2990
  • Loading branch information
mp911de committed Nov 29, 2023
1 parent 197e4cc commit 295d14e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered {
@Override
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {

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

if (!KotlinDetector.isKotlinReflectPresent() || !KotlinDetector.isKotlinType(beanClass)) {
return null;
}


KClass<?> kotlinClass = JvmClassMappingKt.getKotlinClass(beanClass);
List<PropertyDescriptor> pds = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class KotlinBeanInfoFactoryUnitTests {
assertThat(pds).hasSize(1).extracting("name").containsOnly("firstname")
}

@Test // GH-2990
internal fun backsOffForEnums() {

val pds = BeanUtils.getPropertyDescriptors(MyEnum::class.java)

assertThat(pds).extracting("name").contains("ordinal")
}

data class SimpleDataClass(val id: String, var name: String)

@JvmInline
Expand All @@ -86,4 +94,8 @@ class KotlinBeanInfoFactoryUnitTests {
fun getFirstname(): String
}

enum class MyEnum {
Foo, Bar
}

}

0 comments on commit 295d14e

Please sign in to comment.