Firebase @Exclude with kotlin data class

后端 未结 2 1767
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 19:21

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)
         


        
2条回答
  •  耶瑟儿~
    2021-01-07 19:38

    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.

提交回复
热议问题