I'm trying to get javalin to use kotlinx.serializa...
# serialization
c
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?
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
Use
serializer(typeOf<T>)
But caveat, that method only works for serializers that are available at compile time. It doesn’t work for contextual serializers, which includes generics.