Exclude

@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = [ElementType.METHOD, ElementType.FIELD])
public annotationExclude


Marks a field as excluded from the database instance.

Kotlin Note

When applying this annotation to a property of a Kotlin class, the@get use-site target should always be used. There is no need to use the@set use-site target as this annotation isonly considered whenwriting instances into Firestore, and is ignored whenreading instances from Firestore.

Here is an example of a class that can both be written into and read from Firestore whosebar property will never be written into Firestore:

dataclassPojo(varfoo:String?=null,@get:Excludevarbar:String?=null){constructor():this(null,null)//UsedbyFirestoretocreatenewinstances}

If the class only needs to bewritten into Firestore (and not read from Firestore) then the class can be simplified as follows:

dataclassPojo(valfoo:String?=null,@get:Excludevalbar:String?=null)
That is,var can be tightened toval and the secondary no-argument constructor can be omitted.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.