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

Consider making DocumentSnapshot.encodedData() public? #710

Open
martinbonnin opened this issue Mar 10, 2025 · 0 comments
Open

Consider making DocumentSnapshot.encodedData() public? #710

martinbonnin opened this issue Mar 10, 2025 · 0 comments

Comments

@martinbonnin
Copy link

This is a follow up from #500

This also relates to Kotlin/kotlinx.serialization#2223

I also have dynamic content that can be different types:

{
  "value": "someValue"
}

vs

{
  "value": {
    "version": 0,
    "content": "someValue"
  }
}

The only way I found to make it work is to use the internal API:

@file:Suppress(
    "CANNOT_OVERRIDE_INVISIBLE_MEMBER",
    "INVISIBLE_MEMBER",
    "INVISIBLE_REFERENCE",
)

val data = documentSnaphshot.encodedData()

data as Map<String, Any?>
data.forEach {
    if (it.value is String) {
        // case 1
    } else if (it.value is Map<*, *>) {
        // case 2
    } else {
        error("expected a string or a map")
    }
}

From #500 (comment), I understand, this is currently dangerous because the returned data contains native NativeTimestamp values that have different types in commonMain but could those be updated to always return dev.gitlive.firebase.firestore.Timestamp instead?

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

1 participant