Firebase Firestore toObject在布尔属性映射上失败 [英] Firebase Firestore toObject fails on Boolean property mapping

查看:66
本文介绍了Firebase Firestore toObject在布尔属性映射上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从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 called isOpen() and the setter will be called setOpen(). This rule applies for properties of any type, not just Boolean.

也许是Kotlin发行的Firestore?

Maybe a Firestore with Kotlin issue?

推荐答案

尝试将@field:JvmField添加到isValid布尔属性.

Try adding @field:JvmField to isValid boolean property.

这篇关于Firebase Firestore toObject在布尔属性映射上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆