Skip to content
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

Polymorphism is not supported #3

Closed
zigzago opened this issue Oct 5, 2019 · 4 comments
Closed

Polymorphism is not supported #3

zigzago opened this issue Oct 5, 2019 · 4 comments

Comments

@zigzago
Copy link
Collaborator

zigzago commented Oct 5, 2019

I get this stacktrace when I try to serialize a inherited class (as described here https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md )

java.lang.ClassCastException: kotlinx.serialization.UnionKind$POLYMORPHIC cannot be cast to kotlinx.serialization.StructureKind

at com.github.jershell.kbson.BsonEncoder.beginStructure(BsonEncoder.kt:28)
at kotlinx.serialization.PolymorphicSerializer.serialize(Polymorphic.kt:87)
@jershell
Copy link
Owner

jershell commented Oct 6, 2019

Nice, I got it. Will try to implement during week

@jershell
Copy link
Owner

jershell commented Oct 7, 2019

Litote/kmongo#104

@jershell
Copy link
Owner

jershell commented Oct 7, 2019

I implemented it like in kotlinx.serialization.json by "classDiscriminator"(name of the class descriptor property in polymorphic serialization.)

You can look at it in tests
parsePolymorphismSealed()
stringifyPolymorphismSealed()
parsePolymorphismComplexHierarchies()
stringifyPolymorphismComplexHierarchies()
parsePolymorphism()
stringifyPolymorphism()
I take this from their readme https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md

jershell pushed a commit that referenced this issue Oct 7, 2019
@zigzago
Copy link
Collaborator Author

zigzago commented Oct 13, 2019

Thank you

@zigzago zigzago closed this as completed Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants