I need to deserialize 2 versions of an entity `Ent...
# serialization
t
I need to deserialize 2 versions of an entity
Entity
: one with all properties, and another
SimpleEntity
with only the most used properties from
Entity
. How can I do that? I thought of using closed polymorphism but I can't use a discriminator because I don't control the input JSON.
t
Does this mean that I only have to define the following 2 classes •
open class SimpleEntity(val foo: String, ...)
class Entity(foo: String, val bar: Int) : SimpleEntity(foo)
and the dedicated implementation of
JsonContentPolymorphicSerializer
?
d
Yes
t
Alright, I should give it a try. Many thanks for your answers!
I noticed that the custom serializer is not necessary for deserialization as long as I specify the expected subclass explicitly. However it's currently not possible to have a
@Serializable class
extend from a
@Serializable open class
; I ended up using a
sealed class
as base.