Hi, is there way to access the serializer() compan...
# serialization
s
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
Perhaps you want
T::class.serializer()
?
s
@Robert Jaros thanks, yeah that worked. I had to fix the reified type parameter bound to
Any
I was trying to avoid reflection as much as possible as i want to create a native-image (Graal AOT)
thanks for the help.
s
s
@sandwwraith thanks!, will check that.