I'm trying to get javalin to use kotlinx.serialization instead of Jackson. I found this on their github page:
Copy code
JavalinJson.toJsonMapper = object : ToJsonMapper {
override fun map(obj: Any) = { /* Your implementation here */ }
}
I tried this:
Copy code
JavalinJson.fromJsonMapper = object : FromJsonMapper {
override fun <T> map(json: String, targetClass: Class<T>): T {
return Json.parse(T::class.serializer(), json)
}
}
But get
Unresolved reference: serializer
. Is this how to go about it?
crummy
04/23/2020, 11:22 PM
I can call
User.serializer()
OK so I think I've set up the compiler plugin correctly. Just not sure how to do it on a generic.
s
Sam Garfinkel
04/23/2020, 11:53 PM
Use
serializer(typeOf<T>)
Sam Garfinkel
04/23/2020, 11:54 PM
But caveat, that method only works for serializers that are available at compile time. It doesn’t work for contextual serializers, which includes generics.