Description
What is the issue?
With the introduction of Spring Boot 3.2, a behaviour by the KotlinBeanInfoFactory class is causing a problem of ignoring annotated getters in a Kotlin class and instead using getters from its (java) superclass.
How to reproduce?
You can reproduce this issue by creating a class in Kotlin and a superclass in Java. Annotate the getter in the Kotlin subclass with @id and observe that KotlinBeanInfoFactory does not recognize it.
Java Superclass:
public class Animal {
private String name;
// Getters and Setters
}
Kotlin Entityclass:
@Document
@TypeAlias("Dog")
open class DogEntity: Animal() {
@Id
override fun getName(): String {
return super.getName()
}
}
The intent is to enhance a generated java class with a certain field to be the id field of the collection.
Further analysis
KotlinBeanInfoFactory reads properties only from its Kotlin class and disregards any annotated getters. The resulting BeanInfo object includes a PropertyDescriptor for 'name', however, the getter for this property is acquired from the superclass, which does not carry any annotations. Thus, it seems like the 'id' field is not being properly initialized.
What did I expect?
The expected behavior is that KotlinBeanInfoFactory should recognize and prioritize annotated getters in a Kotlin subclass over those in its Java superclass, ensuring proper initialization of the 'id' field and other properties.