Skip to content

Consider making DocumentSnapshot.encodedData() public? #710

Open
@martinbonnin

Description

@martinbonnin

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions