Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

I noted on the console that 'is' is dropped as shown on this snapshot from firestore console enter image description here

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

enter image description here


I noted on the console that 'is' is dropped as shown on this snapshot from firestore console enter image description here

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

enter image description here

like image 396
Tonnie Avatar asked Jul 07 '26 02:07

Tonnie


1 Answers

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").


Update (2026): according to the comments below you nowadays need to use separate annotations for the getter vs setter, so it becomes:

@get:PropertyName("isAccepted") 
@set:PropertyName("isAccepted") 
var isAccepted
like image 174
Frank van Puffelen Avatar answered Jul 08 '26 14:07

Frank van Puffelen