I just did this and it works for my prototype for ...
# random
o
I just did this and it works for my prototype for now.
Copy code
class KClassSerializer<T : Any>(val kClass: KClass<T>) : JsonSerializer<T> {
    override fun serialize(src: T, typeOfSrc: Type, context: JsonSerializationContext) =
            JsonObject().apply {
                kClass.declaredMemberProperties.forEach { addProperty(it.name, it.get(src).toString()) }
            }
}

inline fun <reified T : Any> GsonBuilder.registerKotlinTypeAdapter() = apply {
    registerTypeHierarchyAdapter(T::class.java, KClassSerializer<T>(T::class))
}