Hello! Could anybody please explain what is happen...
# getting-started
z
Hello! Could anybody please explain what is happening here? From this docs: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#open-polymorphism we see that the serializers module keeps in the log
"type"
filed. I did the same thing and for me the module deletes the
"type"
field.
a
The example has explicitly set the type of
val data
to be
Project
, which is polymorphic.
Copy code
val data: Project = OwnedProject("kotlinx.coroutines", "kotlin")
while in your code
val data
has an inferred type of
OwnedProject
, which is not polymorphic and does not require a
type
field
Copy code
val data = OwnedProject("kotlinx.coroutines", "kotlin")
🫠 1
z
Really 🤦 thanks! Another way:
Copy code
val data = OwnedProject("kotlinx.coroutines", "kotlin")
println(format.encodeToString<Project>(data))
👍 1
blob think smart 1
j
Oof! Just lost an hour over this, thanks a lot @Adam S!
fist bump 1