File tree Expand file tree Collapse file tree 4 files changed +87
-2
lines changed
firebase-firestore/src/main/java/com/google/firebase/firestore Expand file tree Collapse file tree 4 files changed +87
-2
lines changed Original file line number Diff line number Diff line change 4343 * WriteBatch#set(DocumentReference, Object)}), the property annotated by {@code @DocumentId} is
4444 * ignored, which allows writing the POJO back to any document, even if it's not the origin of the
4545 * POJO.
46+ *
47+ * <h3>Kotlin Note</h3>
48+ * When applying this annotation to a property of a Kotlin class, the {@code @set} use-site target
49+ * should always be used. There is no need to use the {@code @get} use-site target as this
50+ * annotation is <em>only</em> considered when <em>reading</em> instances from Firestore, and is
51+ * ignored when <em>writing</em> instances into Firestore.
52+ * <p>
53+ * Here is an example of a class that can both be written into and read from Firestore whose
54+ * {@code foo} property will be populated with the Document ID when being read and will be ignored
55+ * when being written into Firestore:
56+ * <pre>
57+ * data class Pojo(@set:DocumentId var foo: String? = null) {
58+ * constructor() : this(null) // Used by Firestore to create new instances
59+ * }
60+ * </pre>
4661 */
4762@ Retention (RetentionPolicy .RUNTIME )
4863@ Target ({ElementType .FIELD , ElementType .METHOD })
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} use-site target
27+ * should always be used. There is no need to use the {@code @set} use-site target as this
28+ * annotation is <em>only</em> considered when <em>writing</em> instances into Firestore, and is
29+ * 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} 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} can be tightened to {@code val} and the secondary no-argument constructor
45+ * 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} and
27+ * {@code @set} 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} property will be stored into and read from a field named {@code my_foo} in the
31+ * Firestore document:
32+ * <pre>
33+ * data class Pojo(@get:PropertyName("my_foo") @set:PropertyName("my_foo") var foo: String? = null) {
34+ * constructor() : this(null) // Used by Firestore to create new instances
35+ * }
36+ * </pre>
37+ * <p>
38+ * If the class only needs to be <em>written</em> into Firestore (and not read from Firestore) then
39+ * the class can be simplified as follows:
40+ * <pre>
41+ * data class Pojo(@get:PropertyName("my_foo") val foo: String? = null)
42+ * </pre>
43+ * That is, {@code var} can be tightened to {@code val}, the secondary no-argument constructor can
44+ * be omitted, and the {@code @set} use-site target can be omitted.
45+ */
2346@ Retention (RetentionPolicy .RUNTIME )
2447@ Target ({ElementType .METHOD , ElementType .FIELD })
2548public @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} use-site target
29+ * should always be used. There is no need to use the {@code @set} use-site target as this
30+ * annotation is <em>only</em> considered when <em>writing</em> instances into Firestore, and is
31+ * 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} property will be populated with the server timestamp in Firestore if its value is
35+ * 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} can be tightened to {@code val} and the secondary no-argument constructor
48+ * 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