android - Firebase Firestore toObject 在 bool 属性映射上失败

标签 android firebase kotlin google-cloud-firestore

在从 Firestore 中提取数据时,我使用 .toObject() 将接收到的数据映射到我的数据类中,即:

data class Img(var event_uid: String = "", var isVip: Boolean = false , var nombre: String = "", var url: String = "")

但是,映射效果不佳。我在任务中收到了字段 isVip=>true,但对象字段被映射为 false(默认值)。

snapshot data

list of mapped object

我做错了什么?

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

可能是带有 Kotlin 问题的 Firestore?

最佳答案

尝试将 @field:JvmField 添加到 isValid bool 属性。

关于android - Firebase Firestore toObject 在 bool 属性映射上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52284861/

相关文章:

kotlin - kotlin 箭头函数式编程中的 Monad 是什么?

java - java 中 Kotlin 中 <?,?> 的等价物是什么?

generics - Kotlin 有没有不是 Any 子类型的东西

android - usingOAuth2 产生错误

android - 在 grails 和 griffon 项目之间共享域和服务类

android - 绑定(bind)套接字安卓

android - 如何从 firebase 数据库中获取嵌套数据

android - 发送数据到网站-Android

javascript - React 函数不渲染

firebase - 如何为连续的数据流提供连续的 Firebase 云功能?