commonMain.dev.gitlive.firebase.firestore.DocumentReferenceSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebase-firestore Show documentation
Show all versions of firebase-firestore Show documentation
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the Firebase Android SDK Kotlin Extensions but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting iOS, Android or JS.
package dev.gitlive.firebase.firestore
import dev.gitlive.firebase.firestore.internal.NativeDocumentReference
import dev.gitlive.firebase.internal.FirebaseEncoder
import dev.gitlive.firebase.internal.SpecialValueSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
/**
* A serializer for [DocumentReference]. If used with [FirebaseEncoder] performs serialization using native Firebase mechanisms.
*/
public object DocumentReferenceSerializer : KSerializer by SpecialValueSerializer(
serialName = "DocumentReference",
toNativeValue = { it.native.nativeValue },
fromNativeValue = { value ->
when (value) {
is NativeDocumentReferenceType -> DocumentReference(NativeDocumentReference(value))
else -> throw SerializationException("Cannot deserialize $value")
}
},
)