-
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
Fix dynamic serialization for nullable values #1199
Fix dynamic serialization for nullable values #1199
Conversation
…c dynamic serialization
…ic dynamic serialization, and support encodeDefaults
encodeAndDecode(Sealed.serializer(), nullChild, objectJson) { | ||
assertEquals("nullable_child", this.type) | ||
assertEquals(nullChild.nullable, this.nullable) | ||
assertEquals(nullChild.intField, this.intField) | ||
assertEquals(3, fieldsCount(this)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This specific test is what was failing before.
It works fine for non-null values and/or array-based serialization, but was throwing a TypeError: Cannot convert undefined or null to object
when it tried js("Object").keys(null)
with object-based serialization
@shanshin This is my first contribution into |
formats/json/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt
Show resolved
Hide resolved
formats/json/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt
Show resolved
Hide resolved
formats/json/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt
Outdated
Show resolved
Hide resolved
formats/json/jsTest/src/kotlinx/serialization/json/DynamicPolymorphismTest.kt
Show resolved
Hide resolved
Co-authored-by: Leonid Startsev <[email protected]>
Fixes #1198
Also adds tests to verify that other potential edge cases work as intended (empty lists, default parameters)
Updates kdoc comments to remove outdated disclaimer that polymorphism is not supported.