Firestore-如何在Kotlin中排除数据类对象的字段 [英] Firestore - how to exclude fields of data class objects in Kotlin
本文介绍了Firestore-如何在Kotlin中排除数据类对象的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Firestore在这里说明了如何使用简单的类将它们直接用于firestore:
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
如何将字段标记为已排除?
How can I mark a field as excluded?
data class Parent(var name: String? = null) {
// don't save this field directly
var questions: ArrayList<String> = ArrayList()
}
推荐答案
由于Kotlin为字段创建了隐式的getter和setter,因此您需要使用
Since Kotlin creates implicit getters and setters for fields, you need to annotate the setter with @Exclude to tell Firestore not to use them. Kotlin's syntax for this is as follows:
data class Parent(var name: String? = null) {
// questions will not be serialized in either direction.
var questions: ArrayList<Child> = ArrayList()
@Exclude get
}
这篇关于Firestore-如何在Kotlin中排除数据类对象的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文