Firebase Firestore toObject在布尔属性映射上失败 [英] Firebase Firestore toObject fails on Boolean property mapping
问题描述
从Firestore中提取数据时,我使用.toObject()
将接收到的数据映射到我的数据类中,即:
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 = "", var isVip: Boolean = false , var nombre: String = "", var url: String = "")
但是,映射效果不佳.我在任务中收到了字段isVip=>true
,但是对象字段被映射为false(默认值).
However, the mapping is not doing well. I received the field isVip=>true
in the task, but the object field is mapped as false (default value).
我在做什么错了?
我在Logcat中看到
I see in Logcat
W/Firestore: (0.6.6-dev) [zzevb]: No setter/field for isVip found on class ***.model.Img
根据 Kotlin Docu :
如果属性的名称以is开头,则使用不同的名称映射 使用规则:getter的名称将与属性相同 名称,设置器的名称将通过替换为 放.例如,对于属性
isOpen
,getter将被调用isOpen()
和设置器将称为setOpen()
.本规则适用 适用于任何类型的属性,而不仅仅是Boolean
.
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?
Maybe a Firestore with Kotlin issue?
推荐答案
尝试将@field:JvmField
添加到isValid
布尔属性.
Try adding @field:JvmField
to isValid
boolean property.
这篇关于Firebase Firestore toObject在布尔属性映射上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!