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

查看:31
本文介绍了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 文档:

如果属性名称以is开头,则为不同的名称映射使用规则:getter 的名称将与属性相同名称,setter 的名称将通过替换 is 获得放.例如,对于属性 isOpen,getter 将被调用isOpen() 并且 setter 将被称为 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天全站免登陆