I have a method that accepts java.lang.reflect.Met...
# announcements
w
I have a method that accepts java.lang.reflect.Method and I'm trying to check whether the method is returning a nullable type or not (via 'kotlinFunction.returnType.isMarkedNullable'). However, for data classes, there are the componentX() methods and the corresponding getter methods, getXXX(). Interestingly for getter functions there is no kotlinFunction.
d
wjur: Kotlin does not really see those as functions, they are part of the property. So they are a
KProperty
, not a
KFunction
.
w
I see. Anyway I need to link a getter with a property 😞
I'm writing a module for jackson.
The
JsonProperty
annotation has a
required
property, which defaults to
false
.
d
Not sure I am following you, what do you mean by "link"?
w
In Kotlin and data classes, this makes a little sense, because it is
isMarkedNullable
that defines whether the property is required or not.
Consider a sample json model:
Copy code
data class Model(
    @JsonProperty("name")
    val name: String
)
The property says that name is an optional field
while the field is required because is of a non nullable type
d
Ok, so, you want to go from the java.lang.reflect.Method for the getter to the corresponding KProperty?
w
Yes
d
Since there is only a way to go from Kotlin reflection to Java reflection you have to get all the properties in the class and search through them until
property.getter.javaMethod == yourMethod
w
It's working!
You saved The World!
Thank you so much!