-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polymorphic (de)serialization crashes with inline class #2049
Comments
The problem is actually on the side of initial serialization — it should be prohibited. As a workaround, you can switch to |
Is it possible to do this with a custom serializer for the value class? I had tried a simple one (with PrimitiveKind.String), but that only lead me toward I am hesitant about
|
To answer my own question: polymorphic serialization of value class works with non-PrimitiveKind custom serializer. Ultimately, the best approach for my particular use case may be a custom serializer at the sealed interface level. |
After giving it a second thought, I can say that problem with the writing of a value class is a duplicate of #1774. Once it is fixed, it would be possible to write a value class (without a discriminator, though). It is still impossible to read it back automatically, but you can fix it with a custom content-based serializer like here: #2159 |
Describe the bug
A sealed interface hierarchy containing an inline class fails on polymorphic (de)serialization. Depending on specific (de)serialization method used, different errors occur:
With decodeFromString():
kotlinx.serialization.json.internal.JsonDecodingException: Expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of MyPoly, but had class kotlinx.serialization.json.JsonLiteral (Kotlin reflection is not available)
With encodeToJsonElement():
kotlinx.serialization.SerializationException: No tag in stack for requested element
To Reproduce
Environment
As for a workaround: is there anything simple besides turning the inline class into a data class?
The text was updated successfully, but these errors were encountered: