firebase-kotlin-sdk
firebase-kotlin-sdk copied to clipboard
Consider making `DocumentSnapshot.encodedData()` public?
trafficstars
This is a follow up from https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/500
This also relates to https://github.com/Kotlin/kotlinx.serialization/issues/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 https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/500#issuecomment-2129174841, 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?