kotlinx.serialization: issue with multi-level sealed class
See original GitHub issueSay you need to insertMany elements of a sealed class from a list, you’ll just pass it and I’d expect the field/key type (or ___type as modified by KMongo) to be present in the root of each document.
Since com.mongodb.internal.operation.Operations::insertMany at line 360 treats the serialization of objects as single elements instead of a whole list, the serializer used is the one of the single elements, thus loosing the generation field type.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Inconsistent behaviour with sealed classes serialization #1194
I faced a problem with sealed classes serialization. To Reproduce import kotlinx.serialization.Serializable import kotlinx.serialization.
Read more >can I use kotlinx serializer with multiple sealed class levels as ...
Every time I try to run this I get an error... Class 'MyContent' is not registered for polymorphic serialization in the scope of...
Read more >Third-party sealed classes serialization with `kotlinx ... - Medium
This is unfortunate because it is impossible to annotate 3rd party subclasses, they are simply out of reach. There are essentially two ways...
Read more >Serialization for sealed classes gives different results when ...
Serialization for sealed classes gives different results when used through Ktor. Steps to reproduce the behavior: Create class with list:
Read more >[Solved]-can I use kotlinx serializer with multiple sealed class ...
Coding example for the question can I use kotlinx serializer with multiple sealed class levels as parents and a nested invocation?-kotlin.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There is a bug with kotlinx.serialization and sealed class with more than one level. Workaround: remove the sealed mention except on the root class:
see #248