I have kotlin data class
data class Client(
val name: String = \"\",
val email: String = \"\",
val phone: String =\"\") {
constructor():this(\"
Here is how I solved the problem.
data class Client(
val name: String = "",
val email: String = "",
val phone: String ="",
@get:Exclude var id: String = "") {
constructor():this("","","")
}
I use @get:Exclude on the id to make sure the id doesn't get sent to Firestore on save, and then when fetching the list of clients do:
snapshot.documents.mapTo(list) {
var obj = it.toObject(Client::class.java)
obj.id = it.id
obj
}
Setting the id of the new object to the id of the document reference.