从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

我做错了什么?

编辑:

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.

Maybe a Firestore with Kotlin issue?

推荐答案

Try adding @field:JvmField to isValid boolean property.

Kotlin相关问答推荐

Mockk:对同一函数进行两次存根会忽略第一个行为

同时也是一个字符串的 Kotlin 枚举

在 Kotlin 中将两个字节转换为 UIn16

如何使用 Firebase 和 Kotlin 在文本 (Jetpack Compose) 中显示当前用户名?

使用启动或使用 coroutineScope 启动协程之间的区别

如何判断给定字符串是否多次包含另一个子字符串?

奇怪的 cotlin check Not Null 参数错误

Kotlin 日期格式从一种更改为另一种

如何使用 Kotlin KClass 属性 simpleName 生成空值

Kotlin 插件错误:无法为类 org.jetbrains.kotlin.gradle.tasks.KotlinCompile 生成代理类

Kotlin 有 array.indexOf 但我无法弄清楚如何做 array.indexOfBy { lambda }

片段内的 Kotlin 按钮 onClickListener 事件

Firebase 权限被拒绝

launch 仅从 Kotlin 1.3 开始可用,不能在 Kotlin 1.2 中使用

Kotlin协程处理错误和实现

Kotlin 接口属性:只需要公共 getter 而没有公共 setter

使用导航组件在不同的图形之间导航

什么是 Kotlin 等价于 Class<?>

用 kotlin 学习 Android MVVM 架构组件

如何在 firebase 数据库中使用 kotlin 协程