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:
@@ -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<>();
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user