We might have property/field sequenceNumber
and we want to save it as sequence_number
in Firestore.
Use @PropertyName annotations on the getter and setter generated by Kotlin.
NOTE: Read about Kotlin Annotation Use-site Targets
class Test ( @get:PropertyName("sequence_number") @set:PropertyName("sequence_number") var sequenceNumber: Int = 0)
or
Use @JvmField (not to generate setter/getter for this property) with @PropertyName
.
class Test ( @JvmField @PropertyName("sequence_number") var sequenceNumber: Int = 0)
NOTE: I have filed an issue to Google to check if this is the intended behaviour and syntax. Tested with com.google.firebase:firebase-firestore:18.0.1
.
class Test ( @PropertyName("sequence_number") var sequenceNumber: Int = 0)
NOTE: @PropertyName
doesn't work here, as sequenceNumber
is saved in Firestore instead of sequence_number
class Test ( @get:PropertyName("sequence_number") var sequenceNumber: Int = 0)
NOTE: @get:PropertyName
is insufficient, where save is succesful but retrieval of the saved value will fail.