Firestore Exclude/Ignore Property From Save (Kotlin)

March 1, 2019
Why @Exclude and @IgnoreExtraProperties doesn’t work

To exclude a field/property from Firebase, you need to use @get:Exclude.

class Test(
    var name: String = "",
    @get:Exclude val isLocalFlag: Boolean = true
) {
    @get:Exclude
    val notLocalFlag: Boolean
        get() = !isLocalFlag
}

@IgnoreExtraProperties and @Exclude doesn’t seems to work, probably because getter is generated by Kotlin.

NOTE: Firestore Annotations

@IgnoreExtraProperties
class Test(
    @Exclude val excludeNotWorking: Boolean = true, // fail
    @get:Exclude val isLocalFlag: Boolean = true
) {
    val ignoreExtraPropertiesNotWorking: Boolean // fail
        get() = !isLocalFlag

    @get:Exclude
    val notLocalFlag: Boolean
        get() = !isLocalFlag
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.