When deserializing lists of polymorphic items, is ...
# serialization
s
When deserializing lists of polymorphic items, is it a way to set a default/fallback through annotations, or do I need to manually register it in the
SerializersModule
? Like for the following example:
Copy code
@Serializable sealed interface Parent

@Serializable @SerialName("child1") data class Child1(val value: Int)
@Serializable @SerialName("child2") data class Child2(val value: String)
@Serializable data object Unknown : Parent

@Serializable data class Response(val items: List<Parent>)
I know I can do this, but if there's a simpler way that keeps everything in the same place, I would prefer that.
Copy code
Json {
  serializersModule = SerializersModule {
    polymorphic(Parent::class) {
      defaultDeserializer { Unknown.serializer() }
    }
  }
}