Firebase Firestore toObject fails on Boolean property mapping

前端 未结 2 856
遥遥无期
遥遥无期 2020-12-18 23:09

When pulling data from Firestore, I use .toObject() to map the data received into my data class, which is:

data class Img(var event_uid: String          


        
相关标签:
2条回答
  • 2020-12-18 23:59

    If you are using in your model class a field named isVip which is of type Boolean, when instantiating an object of your Img class using the following line of code:

    val img = Img("Y9X ... zYn", true, "Nombre", "https://...")
    

    The way in which your isVip property will look like in your database will be simply: vip and not isVip as you probably expected. The resason that your isVip property is stored as isVip and not just vip is because you didn't add your data in the database using your helper class but somehow manually.

    The reason you have that warning is because you have in your database a field which has no correspondent in your model class. In your model class you have a field named isVip which should have in the database a correspondent field named vip and not isVip, as it is now. So Firestore cannot create a connection between those fields and that's why you have that warning.

    To solve this, you can remove (if is possible) the old data from your database and add fresh data using your model class. You need to have the name of your property in your model class named isVip and in your database just only vip.

    Or you can change the name of your property in your modelc class from isVip to simply vip and that's it.

    0 讨论(0)
  • 2020-12-19 00:15

    Try adding @field:JvmField to isValid boolean property.

    0 讨论(0)
提交回复
热议问题