File tree Expand file tree Collapse file tree 3 files changed +76
-2
lines changed
firebase-firestore/src/main/java/com/google/firebase/firestore Expand file tree Collapse file tree 3 files changed +76
-2
lines changed Original file line number Diff line number Diff line change 1919import java .lang .annotation .RetentionPolicy ;
2020import java .lang .annotation .Target ;
2121
22- /** Marks a field as excluded from the database instance. */
22+ /**
23+ * Marks a field as excluded from the database instance.
24+ *
25+ * <h3>Kotlin Note</h3>
26+ * When applying this annotation to a property of a Kotlin class, the <code>@get</code> use-site
27+ * target should always be used. There is no need to use the <code>@set</code> use-site target as
28+ * this annotation is <em>only</em> considered when <em>writing</em> instances into Firestore, and
29+ * is ignored when <em>reading</em> instances from Firestore.
30+ * <p>
31+ * Here is an example of a class that can both be written into and read from Firestore whose
32+ * <code>bar</code> property will never be written into Firestore:
33+ * <pre>
34+ * data class Pojo(var foo: String? = null, @get:Exclude var bar: String? = null) {
35+ * constructor() : this(null, null) // Used by Firestore to create new instances
36+ * }
37+ * </pre>
38+ * <p>
39+ * If the class only needs to be <em>written</em> into Firestore (and not read from Firestore) then
40+ * the class can be simplified as follows:
41+ * <pre>
42+ * data class Pojo(val foo: String? = null, @get:Exclude val bar: String? = null)
43+ * </pre>
44+ * That is, <code>var</code> can be tightened to <code>val</code> and the secondary no-argument
45+ * constructor can be omitted.
46+ */
2347@ Retention (RetentionPolicy .RUNTIME )
2448@ Target ({ElementType .METHOD , ElementType .FIELD })
2549public @interface Exclude {}
Original file line number Diff line number Diff line change 1919import java .lang .annotation .RetentionPolicy ;
2020import java .lang .annotation .Target ;
2121
22- /** Marks a field to be renamed when serialized. */
22+ /**
23+ * Marks a field to be renamed when serialized.
24+ *
25+ * <h3>Kotlin Note</h3>
26+ * When applying this annotation to a property of a Kotlin class, both the <code>@get</code> and
27+ * <code>@set</code> use-site targets should be used.
28+ * <p>
29+ * Here is an example of a class that can both be written into and read from Firestore whose
30+ * <code>foo</code> property will be stored into and read from a field named "my_foo" in the
31+ * Firestore document:
32+ * <pre>
33+ * data class Pojo(
34+ * @get:PropertyName("my_foo")
35+ * @set:PropertyName("my_foo")
36+ * var foo: String? = null
37+ * ) {
38+ * constructor() : this(null) // Used by Firestore to create new instances
39+ * }
40+ * </pre>
41+ * <p>
42+ * If the class only needs to be <em>written</em> into Firestore (and not read from Firestore) then
43+ * the class can be simplified as follows:
44+ * <pre>
45+ * data class Pojo(@get:PropertyName("my_foo") val foo: String? = null)
46+ * </pre>
47+ * That is, <code>var</code> can be tightened to <code>val</code>, the secondary no-argument
48+ * constructor can be omitted, and the <code>@set</code> use-site target can be omitted.
49+ */
2350@ Retention (RetentionPolicy .RUNTIME )
2451@ Target ({ElementType .METHOD , ElementType .FIELD })
2552public @interface PropertyName {
Original file line number Diff line number Diff line change 2323 * Annotation used to mark a timestamp field to be populated with a server timestamp. If a POJO
2424 * being written contains {@code null} for a @ServerTimestamp-annotated field, it will be replaced
2525 * with a server-generated timestamp.
26+ *
27+ * <h3>Kotlin Note</h3>
28+ * When applying this annotation to a property of a Kotlin class, the <code>@get</code> use-site
29+ * target should always be used. There is no need to use the <code>@set</code> use-site target as
30+ * this annotation is <em>only</em> considered when <em>writing</em> instances into Firestore, and
31+ * is ignored when <em>reading</em> instances from Firestore.
32+ * <p>
33+ * Here is an example of a class that can both be written into and read from Firestore whose
34+ * <code>foo</code> property will be populated with the server timestamp in Firestore if its value
35+ * is null:
36+ * <pre>
37+ * data class Pojo(@get:ServerTimestamp var foo: Timestamp? = null) {
38+ * constructor() : this(null) // Used by Firestore to create new instances
39+ * }
40+ * </pre>
41+ * <p>
42+ * If the class only needs to be <em>written</em> into Firestore (and not read from Firestore) then
43+ * the class can be simplified as follows:
44+ * <pre>
45+ * data class Pojo(@get:ServerTimestamp val foo: Timestamp? = null)
46+ * </pre>
47+ * That is, <code>var</code> can be tightened to <code>val</code> and the secondary no-argument
48+ * constructor can be omitted.
2649 */
2750@ Retention (RetentionPolicy .RUNTIME )
2851@ Target ({ElementType .METHOD , ElementType .FIELD })
You can’t perform that action at this time.
0 commit comments