-
Notifications
You must be signed in to change notification settings - Fork 154
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
Serialize sealed classes #271
Serialize sealed classes #271
Conversation
Hey @iruizmar this look good! Lets get the tests working for you so you can add coverage for your changes, how are you trying to run the tests exactly? |
Hey @nbransby ! 👋🏻 Thanks for the quick response. I'm just trying to run them through Android Studio by clicking on Play on the test suite class: I tried running the |
Have you tried in IJ instead? |
Same experience there :(. Are you doing the same or are you running them any other way? |
I think I got them running now by using the |
Hey @nbransby! 👋🏻 As you can see on the tests, the serialization is adding a I would expect the resultant map to be:
and not
WDYT? It's not a problem when you're encoding and decoding here because it's decoding the same way, though. Please, let me know if there's something else to be done. |
Maybe the docs have been simplified for reading as if it did add type at the same level then it could clash with a property called type if the class had such. But best way to verify that would be to see what the json serializer produces in a kotlin playground for the examples given in the docs |
I tested the
Without the
|
Yes I believe it will be a problem as perhaps only the properties under value is what gets persisted to firestore/rtdb etc |
…r/firebase-kotlin-sdk into serialize_sealed_classes
Yeah which kinda sucks as you would expect the format in firestore to be the same as the json format, out of interest what happens with the json format if you do have a property called type on the class? We are going to need to modify the FirebaseEncoder and FirebaseDecoder to stop it adding the value properly |
Hey @nbransby Trying to encode with json an object with a Could you point me towards where that |
So we probably need to support a classDiscriminator parameter just like we support shouldEncodeElementDefault. As for where the value property is added I don't believe that's explicitly done in our code and is likely just a quirk of our (mis?)use of the serialization APIs. I had a look at the code myself but it's been quite a while since I worked on it so afraid there's not much more I can give in the way of pointers |
Hey! So this will require a bit more of work than I expected 😓 . I'll try to investigate the origin of the |
yes can make it optional just like shouldEncodeElementDefault you will also need it in decode. |
Hey man @nbransby |
Can plus use the play buttons in the gutter for the tests you want to run but you need to make sure you have the emulator setup correctly for it to succeed, you can check the GitHub pull request action in .GitHub to see the setup required |
Its because they are not unit tests but connected device tests that run on the emulator you can run the task connectedDebugAndroidTest or read up on them to find out to run and debug individual tests from the ide |
…es' of https://github.com/iruizmar/firebase-kotlin-sdk into serialize_sealed_classes
Hey @nbransby 👋🏻 |
What about support for classDiscriminator? Via an annotation is cool and is prefered to an optional config param but do you think we should still provide the alternative like kotlinx.serialization.json does? |
Also need to add the details about the FIrebaseClassDiscriminator annotation to the readme 👍 |
I'm OK with adding the Right now, the serialization of Is that what you're looking for? I added the section on the Readme :) |
@nbransby Any news on this one? Does the docs look good enough for you? |
@iruizmar could you add comments with links to the code that inspired you? that would help me and others understand the code in the future |
…r/firebase-kotlin-sdk into serialize_sealed_classes
@nbransby Done! It's basically the whole Polymorphic.kt file |
Thanks @iruizmar, good stuff! |
Solves #190 and #61
I haven't unit tested it because it's saying to me that "Tests events were not received". If you have any idea on how to fix this, I could certainly add the testing.