-
Notifications
You must be signed in to change notification settings - Fork 636
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
Sealed value class is serialized/deserialized incorrectly with default json polymorphism style #2938
Comments
Hello, I'd like to fix this issue. |
@Stream29 To "fix" the issue, the question needs to be what the correct serialization form should be. Should it revert to the array form of polymorphism? |
…alized polymorphically with 'type' parameter Associated issue: [issue-2938](Kotlin#2938)
Associated issue: [issue-2938](Kotlin#2938)
…alized polymorphically with 'type' parameter Associated issue: [issue-2938](Kotlin#2938) (cherry picked from commit 71b38d9)
Associated issue: [issue-2938](Kotlin#2938) (cherry picked from commit d83fe73)
Yes, so I add a error when serializing value class polymorphically. |
The decision to allow serialization of value class over primitive to (somewhat) incorrect form was deliberate: see #2049 (comment). Yes, we currently cannot deserialize such data back. We plan to address it systematically (as a part of #2835, most likely) rather than prohibiting writing such data completely. Besides, introducing such an exception would be a breaking change in the library. |
Thank you for replying! |
Describe the bug
Value class that contains a primitive value cannot be serialized polymorphically with 'type' parameter.
The kotlinx.serialization-json library does not mention it and produces incorrect behaviour.
To Reproduce
This code outputs:
and then throw exception:
Expected behavior
When facing the sealed value class that contains primitive type, a exception should be thrown directly, like the exception on sealed enum:
Environment
The text was updated successfully, but these errors were encountered: