Issue with polymorphism and KMM: Setup is ```inte...
# serialization
Issue with polymorphism and KMM: Setup is
Copy code
interface IFoo 

class FooA: IFoo

class FooB: IFoo
Copy code
val myJson = Json {
    ignoreUnknownKeys = true
    isLenient = true
    explicitNulls = false
    encodeDefaults = false
    serializersModule = SerializersModule {
        polymorphic(IFoo::class, FooA::class, FooA.serializer())
        polymorphic(IFoo::class, FooB::class, FooB.serializer())
Copy code
val listOfFoo = myJson.decodeFromString<<List<IFoo>>(...)
The above ^ works fine in the Android code, but errors out when called from iOS:
`kotlinx.serialization.SerializationException: Serializer for class ‘IFoo’ is not found.
Mark the class as @Serializable or provide the serializer explicitly.
On Kotlin/Native explicitly declared serializer should be used for interfaces and enums without @Serializable annotation`
Is there a step that I am missing with setting up the SerializersModule to make it compatible with iOS? Again, this works perfectly fine from the Android Versions: • Kotlin: 1.7.10 • Kotlin serialization: 1.4.0 ◦ org.jetbrains.kotlinx:kotlinx-serialization-core ◦ org.jetbrains.kotlinx:kotlinx-serialization-json EDIT: I found this older post with someone asking the same question and they seemed to solve it by downgrading ?
Update: I solved this 2 ways. 1. You provide an explicit serializer. Instead of putting
you have to do
myJson.decodeFromString(ListSerializer(PolymorphicSerializer(IFoo::class)), jsonString)
2. You make the interface an abstract class Resources that led me here: •