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

Failing sealed class list encoding / decoding tests #365

Merged
merged 9 commits into from
May 24, 2023

Conversation

brahyam
Copy link
Contributor

@brahyam brahyam commented Apr 7, 2023

Hi!,

Thanks a lot for the huge effort of making available this library.

While using the SDK to store a list of sealed classes I ran into the following error on decoding.
NullPointerException: null cannot be cast to non-null type kotlin.collections.Map<*, *>

I managed to track it to firebase-common/androidMain/_decoders.kt FirebaseDecoder.structureDecoder function. (and also its iOS equivalent)

It happens because the descriptor is expecting a value property that was not encoded. I managed to fix it with the following

StructureKind.CLASS, StructureKind.OBJECT, PolymorphicKind.SEALED -> (value as Map<*, *>).let { map ->
        FirebaseClassDecoder(decodeDouble, map.size, { map.containsKey(it) }) { desc, index ->
            val elementName = desc.getElementName(index)
            if (desc.kind is PolymorphicKind && elementName == "value") {
                map
            } else {
                map[desc.getElementName(index)]
            }
        }
    }

And similar for the iOS but maybe there is a more elegant way?

I will open an issue with the same comment and link this PR

@Reedyuk
Copy link
Collaborator

Reedyuk commented Apr 9, 2023

Can you fix the build failure please.

@brahyam
Copy link
Contributor Author

brahyam commented Apr 12, 2023

@Reedyuk should work now 🙌🏽

@Reedyuk
Copy link
Collaborator

Reedyuk commented Apr 12, 2023

@nbransby

@brahyam
Copy link
Contributor Author

brahyam commented Apr 21, 2023

@Reedyuk @nbransby any chance it could be merged soon? 🙏🏼

@Reedyuk
Copy link
Collaborator

Reedyuk commented Apr 21, 2023

I approved, it's on @nbransby

@nbransby nbransby self-requested a review April 21, 2023 11:18
Copy link
Member

@nbransby nbransby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be separate tests for encode and decode that use nativeAssertEquals and nativeMapOf like the existing tests - this is because you should be testing that it encodes/decodes to the format expected by firebase native libraries

@brahyam
Copy link
Contributor Author

brahyam commented Apr 21, 2023

@Reedyuk @nbransby I split the encode and decode tests now and I used nativeAssertEquals and nativeMapOf for the encoding as other tests.

@nbransby
Copy link
Member

great stuff!

@Reedyuk
Copy link
Collaborator

Reedyuk commented Apr 22, 2023

@brahyam - does this work for you locally? the ci is getting stuck on the ios tests,

@nbransby
Copy link
Member

I ran it locally and it works

@nbransby nbransby merged commit 9e9d68b into GitLiveApp:master May 24, 2023
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

Successfully merging this pull request may close these issues.

3 participants