IMPORTANT: In July 2025, we stopped releasing new versions of KTX modules, and we removed the KTX libraries from the Firebase Android BoM (v34.0.0). If you use KTX APIs from the previously released KTX modules, we recommend that you migrate your app to use KTX APIs from the main modules instead. For details, see the FAQ about this initiative.
When applying this annotation to a property of a Kotlin class, both the @get and @set use-site targets should be used.
Here is an example of a class that can both be written into and read from Firestore whose foo property will be stored into and read from a field named my_foo in the Firestore document:
dataclassPojo(@get:PropertyName("my_foo")@set:PropertyName("my_foo")varfoo:String?=null){constructor():this(null)// Used by Firestore to create new instances}
If the class only needs to be written into Firestore (and not read from Firestore) then the class can be simplified as follows:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-21 UTC."],[],[],null,["PropertyName\n\n\n```\n@Retention(value = RetentionPolicy.RUNTIME)\n@Target(value = [ElementType.METHOD, ElementType.FIELD])\nannotation PropertyName\n```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nMarks a field to be renamed when serialized.\n\nKotlin Note When applying this annotation to a property of a Kotlin class, both the `@get` and `@set` use-site targets should be used.\n\nHere is an example of a class that can both be written into and read from Firestore whose `foo` property will be stored into and read from a field named `my_foo` in the Firestore document: \n\n```kotlin\ndata class Pojo(@get:PropertyName(\"my_foo\") @set:PropertyName(\"my_foo\") var foo: String? = null) {\n constructor() : this(null) // Used by Firestore to create new instances\n}\n```\n\nIf the class only needs to be *written* into Firestore (and not read from Firestore) then the class can be simplified as follows: \n\n```kotlin\ndata class Pojo(@get:PropertyName(\"my_foo\") val foo: String? = null)\n```\nThat is, `var` can be tightened to `val`, the secondary no-argument constructor can be omitted, and the `@set` use-site target can be omitted.\n\nSummary \n\nPublic functions \n\nvalue \n\n```\nabstract fun value(): String!\n```"]]