Firestore here explains, how I can use simple classes to directly use them with firestore: https://firebase.google.com/docs/firestore/manage-data/add-data

如何将字段标记为已排除?

data class Parent(var name: String? = null) {
    // don't save this field directly
    var questions: ArrayList<String> = ArrayList()
}

推荐答案

因为Kotlin为字段创建了隐式的getter和setter,所以您需要用@Exclude来注释setter,以告诉Firestore不要使用它们.Kotlin的语法如下所示:

data class Parent(var name: String? = null) {
    // questions will not be serialized in either direction.
    var questions: ArrayList<Child> = ArrayList()
        @Exclude get
}

Kotlin相关问答推荐

直接从SON解析NonEmptyList

在Kotlin Jetpack中重用下拉菜单

插入/更新/upsert时不发出房间流

升级使用jOOQ Gradle插件生成代码失败

kotlin 父类具有依赖于抽象变量的变量

如何处理基于枚举提前返回的 forEach 循环,Kotlin 中的一条路径除外

Kotlin 列表扩展功能

为什么没有remember 的 mutableStateOf 有时会起作用?

Picasso 回调

找不到引用的类 kotlin.internal.annotations.AvoidUninitializedObjectCopyingCheck

kotlin 扩展属性的惰性初始化器中的这个引用

Kotlin 中 lambda 表达式中的默认参数

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

Kotlin:找不到符号类片段或其他 android 类

主机名不能为空

参数不匹配;SimpleXML

Kotlin - 是否可以在类中的 init 块之前初始化伴随对象?

Kotlin类型安全类型别名

Kotlin - 错误:Could not find or load main class _DefaultPackage

Kotlin中对象和数据类的区别是什么?