简体   繁体   中英

Drop "is" prefix for Firebase Firestore fields for Boolean Values

When using custom Kotlin objects for firestore drop 'is' prefix. It ruined my entire day.

data class UberRequest(val geoPoint: GeoPoint? = null,
                   
                   //don't use 'is' prefix on boolean properties
                   val isAccepted:Boolean = false,
                   @ServerTimestamp
                   val timestamp: Date? = null)

Firestore uses Java Bean conventions for mapping properties between the Java class and the JSON in the database.

In Java Beans an is prefix on a boolean field/method indicates a boolean property. So the fact that your isAccepted is mapped to a JSON property with the name accepted is expected.


If you want to control the name that Firebase uses in its JSON mapping, you can annotate the field/methods with @PropertyName("isAccepted") .

I noted on the console that 'is' is dropped as shown on this snapshot from firestore console在此处输入图像描述

So when you try to retrieve the isAccepted value it returns the default value which in this case is false . If the default value is null, you get a null value back

This is illustrated on this snapshot from my logcat

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM