Firestore

class Firestore(val bindings: FirebaseFormat.Firestore.Bindings, val serializersModule: SerializersModule = EmptySerializersModule()) : FirebaseFormat(source)

Firestore, following com.google.firebase.firestore.util.CustomClassMapper.

  • Numbers: Int, Long, Float and Double; other numbers and Chars are rejected.

  • Collections: Lists, and Maps with String keys; sets, other collections and arrays are rejected.

  • Enums: the entry's serial name.

  • com.google.firebase.Timestamp and the Bindings.nativeTypes (such as GeoPoint, Blob, DocumentReference and FieldValue) are passed through unchanged, and a kotlin.time.Instant is stored as a Timestamp. In a @Serializable class such properties need kotlinx.serialization's @Contextual, or a file-level @UseContextualSerialization.

  • A @ServerTimestamp property that is null is written as FieldValue.serverTimestamp(), and a @DocumentId property is skipped on writes and receives the document on reads.

  • Rejected values throw an IllegalArgumentException (Could not serialize object. …) on writes and a RuntimeException (Could not deserialize object. …) on reads, naming the path of the offending field.

  • A document property without a class property is logged unless the class has @IgnoreExtraProperties, and fails the read if it has @ThrowOnExtraProperties.

Constructors

Link copied to clipboard
constructor(bindings: FirebaseFormat.Firestore.Bindings, serializersModule: SerializersModule = EmptySerializersModule())

Types

Link copied to clipboard
interface Bindings

The Firestore types this format passes through; provided by the Firestore module.

Properties

Link copied to clipboard
Link copied to clipboard
open override val serializersModule: SerializersModule

Functions

Link copied to clipboard
fun <T : Any> convertToCustomClass(value: Any?, type: KClass<T>, documentReference: Any? = null): T?

Decodes plain values to an instance of type, found by its serializer, as the Android SDK's CustomClassMapper.convertToCustomClass(Object, Class, DocumentReference) does; null stays null. Any and the product's own value types are returned as they are, like Object and a Timestamp on Android.

Link copied to clipboard
fun convertToPlainValue(value: Any?): Any?

Converts value to plain values by its runtime type, as the Android SDK's mapper does with the Object given to calls such as DocumentReference.set(Object): plain values are checked and copied, the product's own value types are passed through and any other object is encoded with the serializer of its class, which must be @Serializable. The type arguments of a generic class are erased at runtime, so such a value goes through encodeToPlainValue, whose serializer knows them.

Link copied to clipboard
fun <T> decodeFromPlainValue(deserializer: DeserializationStrategy<T>, value: Any?, documentReference: Any? = null): T

Decodes plain values to a T with deserializer, as the Android SDK's mapper does in calls such as DocumentSnapshot.toObject(Class). For Firestore, documentReference is the document that @DocumentId properties receive (its id for a String property); it is ignored by the other products.

Link copied to clipboard
inline fun <T> FirebaseFormat.decodeFromPlainValue(value: Any?, documentReference: Any? = null): T

Decodes plain values to a T with the serializer of its type, where Any stands for any plain value.

Link copied to clipboard
fun <T> encodeToPlainValue(serializer: SerializationStrategy<T>, value: T): Any?

Encodes value to plain values with serializer.

Link copied to clipboard
inline fun <T> FirebaseFormat.encodeToPlainValue(value: T): Any?

Encodes value to plain values with the serializer of its type, where Any stands for any plain value.

Link copied to clipboard
fun serializerFor(type: KType): KSerializer<Any?>

The serializer for type, where Any (as in Map<String, Any?>) stands for the plain value itself, as Object does for the Android mapper: it is decoded as is and encoded by its runtime type. The product's own value types are passed through the same way, and the type arguments of a generic class are resolved by this rule too. So is a type without a serializer of its own, such as the Comparable a map of mixed values infers, unless it is the base of a polymorphic hierarchy registered in the serializersModule.