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

Add sealed classes support to serialization #61

Closed
LarsArtmann opened this issue Jul 18, 2020 · 21 comments
Closed

Add sealed classes support to serialization #61

LarsArtmann opened this issue Jul 18, 2020 · 21 comments
Labels
API coverage Request for missing APIs

Comments

@LarsArtmann
Copy link

Could you add support of "sealed" class to the FirebaseDecoder.structureDecoder and FirebaseEncoder.structureEncoder functions?

I would try it with some think like this:

fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor, @Suppress("UNUSED_PARAMETER") vararg typeParams: KSerializer<*>): CompositeEncoder = when(descriptor.kind) {
    StructureKind.LIST, PolymorphicKind.SEALED -> mutableListOf<Any?>()
        .also { value = it }
        .let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity) { _, index, value -> it.add(index, value) } }
    StructureKind.MAP -> mutableListOf<Any?>()
        .let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
    StructureKind.CLASS,  StructureKind.OBJECT -> mutableMapOf<Any?, Any?>()
        .also { value = it }
        .let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity) { _, index, value -> it[descriptor.getElementName(index)] = value } }
    else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
}

This case is optimized for plain Kotlin.

Unfortunately, I also have some building problems too, so I cannot implement them myself

@LarsArtmann LarsArtmann added the API coverage Request for missing APIs label Jul 18, 2020
@LarsArtmann LarsArtmann changed the title Adding PolymorphicKind.SEALED to FirebaseDecoder.structureDecoder / FirebaseEncoder.structureEncoder Adding sealed classes support to serialization Jul 18, 2020
@LarsArtmann LarsArtmann changed the title Adding sealed classes support to serialization Add sealed classes support to serialization Jul 18, 2020
@nbransby
Copy link
Member

What are the building problems you are having?

@LarsArtmann
Copy link
Author

lint is failing

@nbransby
Copy link
Member

What lint?

@LarsArtmann
Copy link
Author

idk, that's the error message:

Execution failed for task ':firebase-firestore:lint'.
> Lint found errors in the project; aborting build.

@nbransby
Copy link
Member

I have not seen this before! is there a way to get the log of lint errors?

@LarsArtmann
Copy link
Author

That's the only thing gradle prints out to the console.
Cloud it is possible that it is a problem with Intelijj and I need to use Android Studio?

@nbransby
Copy link
Member

No, I use IJ but anyway its gradle issue so shouldn't be affected by IDE try running the task with --info

@nbransby
Copy link
Member

Ok I recreated the issue by running the lint task directly - what gradle task were you running?

@LarsArtmann
Copy link
Author

gradle build in firebase-firestore

@nbransby
Copy link
Member

Pull latest master - should fix your issue

@LarsArtmann
Copy link
Author

Now I have this problem: "Expected function 'runTest' has no actual declaration in module firebase-firestore.iosArm64Test~1 (test) for Native"
image

PS: I use Windows 10

@nbransby
Copy link
Member

The error is the screenshot is different, are you using the master branch? It says not defined for JVM target but there is no JVM target

@LarsArtmann
Copy link
Author

Yes I pulled the master branch and merged it with the local changes

@nbransby
Copy link
Member

What local changes do you have?

@LarsArtmann
Copy link
Author

Now I have done, a hard reset to the latest commit on the master branch.
That was my result:
image
image

(I just run firebase-firestore build on IntelliJ 2020.2 Ultimate with Gradle version 5.6.4)

@nbransby
Copy link
Member

Still complaining about JVM platform which we dont have a target setup for so still have no idea how you are getting this error

@nbransby
Copy link
Member

I reproduced this error by running the build task in happens in the task ':firebase-app:compileDebugUnitTestKotlinAndroid' which makes sense as its trying to run uninstrumented android tests on the jvm. Thing is we dont have any uninstrumented android tests and im not sure how to stop it from doing this.

Workaround is to run the assemble task instead, thats what the CI does

@nbransby
Copy link
Member

btw build is working now too

@walkingbrad
Copy link
Contributor

Hey y'all. Is this a fix we can get back into in the pipeline? I just started using this library (which has worked pretty great so far) but there are couple of hitches such as the inability to deserialize to a sealed class (which I might expect is a fairly common expectation today).

@nbransby
Copy link
Member

nbransby commented Apr 6, 2022

closing as support has been added

@nbransby nbransby closed this as completed Apr 6, 2022
@walkingbrad
Copy link
Contributor

This made my day/week! Thank you all for the time/effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API coverage Request for missing APIs
Projects
None yet
Development

No branches or pull requests

3 participants