在从 Firestore 中提取数据时,我使用 .toObject()
将接收到的数据映射到我的数据类中,即:
data class Img(var event_uid: String = "", var isVip: Boolean = false , var nombre: String = "", var url: String = "")
但是,映射效果不佳。我在任务中收到了字段 isVip=>true
,但对象字段被映射为 false(默认值)。
我做错了什么?
编辑: 我在 Logcat 中看到了
W/Firestore: (0.6.6-dev) [zzevb]: No setter/field for isVip found on class ***.model.Img
根据Kotlin Docu :
If the name of the property starts with is, a different name mapping rule is used: the name of the getter will be the same as the property name, and the name of the setter will be obtained by replacing is with set. For example, for a property
isOpen
, the getter will be calledisOpen()
and the setter will be calledsetOpen()
. This rule applies for properties of any type, not justBoolean
.
可能是带有 Kotlin 问题的 Firestore?
最佳答案
尝试将 @field:JvmField
添加到 isValid
bool 属性。
关于android - Firebase Firestore toObject 在 bool 属性映射上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52284861/