I am trying to deserialize a type that is polymorp...
# serialization
e
I am trying to deserialize a type that is polymorphic on one of its properties but cant seem to figure out a way. đŸ§”
I receive a json list of this type
Copy code
@Serializable
class TransformedToken<V>(
  val type: String,
  val name: String,
  val value: V,
  val description: String?,
  val original: Original<V>,
  val attributes: JsonObject,
  val path: List<String>,
  val filePath: String,
  val isSource: Boolean,
)
typeof
value
changes based on
Cant seem to figure out a way to say: “while deserializing
value
, discriminate based on parent’s
type
field” 😞
f
You will beed to write a custom adapter for that. Here are the docs on polymorphism https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md