Back off from Kotlin BeanInfo creation for interfaces.

KotlinBeanInfoFactory no longer creates a BeanInfo for interfaces to follow general BeanInfo semantics.

Closes #2964
This commit is contained in:
Mark Paluch
2023-10-25 11:45:47 +02:00
parent 5dbd956a28
commit f060bcfe34
2 changed files with 17 additions and 0 deletions

View File

@@ -48,10 +48,15 @@ public class KotlinBeanInfoFactory implements BeanInfoFactory, Ordered {
@Override
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
if (beanClass.isInterface()) {
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<>();

View File

@@ -65,6 +65,14 @@ class KotlinBeanInfoFactoryUnitTests {
assertThat(pds[0].writeMethod).isNull()
}
@Test // GH-2964
internal fun backsOffForInterfaces() {
val pds = BeanUtils.getPropertyDescriptors(FirstnameOnly::class.java)
assertThat(pds).hasSize(1).extracting("name").containsOnly("firstname")
}
data class SimpleDataClass(val id: String, var name: String)
@JvmInline
@@ -74,4 +82,8 @@ class KotlinBeanInfoFactoryUnitTests {
data class WithOptionalValueClass(val address: EmailAddress? = EmailAddress("un@known"))
interface FirstnameOnly {
fun getFirstname(): String
}
}