Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore - how to exclude fields of data class objects in Kotlin

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()
}
like image 593
prom85 Avatar asked Mar 11 '18 19:03

prom85


1 Answers

I realize this is super late, but I just stumbled upon this and thought I could provide an alternative syntax, hoping someone will find it helpful.

data class Parent(var name: String? = null) {
    @get:Exclude
    var questions: ArrayList<Child> = ArrayList()
}

One benefit to this is that, in my opinion, it reads a little clearer, but the main benefit is that it would allow excluding properties defined in the data class constructor as well:

data class Parent(
    var name: String? = null,
    @get:Exclude
    var questions: ArrayList<Child> = ArrayList()
)
like image 88
sindrenm Avatar answered Oct 26 '22 07:10

sindrenm