Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase @Exclude with kotlin data class

I have this data class in Kotlin (example):

import com.google.firebase.database.Exclude  data class User(val name: String = "", @Exclude val age: Int = 0) 

And I don't want to save the age property in firebase. @Exclude should do this but it does not work, age is still saved.

Are there any workarounds?

like image 253
Dan S Avatar asked Oct 18 '16 19:10

Dan S


1 Answers

Placing @Exclude on a property targets its generated field and not its generated get accesor method. To do the latter you'll need to prefix "Exclude" with "get:". e.g.:

data class User(val name: String = "", @get:Exclude val age: Int = 0) 

See Annotation Use-site Targets for more details.

like image 61
mfulton26 Avatar answered Sep 23 '22 11:09

mfulton26