Hello, I'm curious, is there an idiomatic way to k...
# serialization
g
Hello, I'm curious, is there an idiomatic way to know at run time if an Any object is serializable ?
c
Automatically? Not really. There are no “marker” annotations, interfaces, or anything else added to serializable classes. On JVM you can look up a serializer via reflection, but that doesn’t work on MPP The “idiomatic” way of knowing if an object is serializable is to pass its KSerializer wherever you’re trying to serialize it
👍 3
g
If I have a set of classes that I know to be Serializable, then how can I do something like:
Copy code
myClassList.map { ... do something with it.serialiser() }
?
t
Not sure what exactly you're trying to do, but maybe solution for you is to use open polymorphic serialization - https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#static-parent-type-lookup-for-polymorphism