I have kotlin data class
data class Client(
val name: String = \"\",
val email: String = \"\",
val phone: String =\"\") {
constructor():this(\"
I just improved the solution of @iCediCe, and add methods to DocumentSnapshot and QuerySnapshot.
interface HasId {
var id : String
}
inline fun DocumentSnapshot.toObjectWithId(): T {
return this.toObject(T::class.java)!!.also {
it.id = this.id
}
}
inline fun QuerySnapshot.toObjectsWithId(): List {
return this.documents.map {
it.toObjectWithId()
}
}
And usage:
data class User(
@get:Exclude
override var id: String,
...
): HasId
val user = documentSnapshot.toObjectWithId()
val users = querySnapshot.toObjectsWithId()