spand
10/02/2020, 9:34 AMkotlinx.serialization.json.Json
object. Can I ask it if it is configured to serialize a given KClass
or if it will throw an exception when encountering instances of that type ?Vsevolod Tolstopyatov [JB]
10/03/2020, 1:26 PMKClass
is marked with @Serializable
? What platform is it?
On JVM, you can check if class has @Serializable
annotation via reflection or if Json.serializersModule.getContextual(KClass) != null
On multiplatform you’ll need an actual T
for that. Then you can use something like Json.serializersModule.serializer<T>()
to see if that returns a value or throwsspand
10/05/2020, 5:42 AM@Serializable
but runtime checked (in a test) when using external serializers ( @Serializer(forClass = ...)
). It is shelved for now but I guess module.serializer<T>()
is the way to go.