Hi, is there way to access the serializer() companion object in a generic way with a reified type? I checked the generated
Serializable
class to see if there is a any common interface. What i am doing is,
Copy code
@Serializable
data class TT(
val ciId: Long = -1,
val ciAttributes: Map<String, String?> = emptyMap()
) {
inline fun <reified T> asType(serializer: KSerializer<T>): T {
return Mapper.unmapNullable(serializer, ciAttributes)
}
}
val t: TT = ....
val x = t.asType(XX.serializer())
r
Robert Jaros
02/26/2020, 6:41 PM
Perhaps you want
T::class.serializer()
?
s
suresh
02/26/2020, 6:52 PM
@Robert Jaros thanks, yeah that worked. I had to fix the reified type parameter bound to
Any
suresh
02/26/2020, 6:53 PM
I was trying to avoid reflection as much as possible as i want to create a native-image (Graal AOT)