firebase-kotlin-sdk
firebase-kotlin-sdk copied to clipboard
DocumentReference serialization not supported?
If you have a reference as a child field of a document, how would one go about serializing/deserializing that reference?
It seems that directly using DocumentReference in your object structure won't work since it is not a @Serializable, and using the referenced document type throws an exception
e.g. in android it throws
java.lang.ClassCastException: com.google.firebase.firestore.DocumentReference cannot be cast to java.util.Map
Trying to figure this one out and any help would be appreciated. I was also looking at creating a potential PR, but hesitated because I'm not confident in the other platforms 🤷
Here's an example problem:
db.collection("things").document("thing").get().data(Thing.serializer())
// ...
@Serializable
data class Thing(
val someRef: DocumentReference // Complains that DocumentReference is not serializable, and can't do @Contextual
)
// or
@Serializable
data class Thing(
val someRef: String // Does not fail, but serializes the reference to the default kotlin .toString() method
)
// or
@Serializable
data class Thing(
val someRef: OtherCollectionDocument // Fails with the error mentioned above
)
we'll need to add specific support for reference fields in the serialization support - how do they work with the standard serialization for android or js, aka what is the expected behavior?