-
Notifications
You must be signed in to change notification settings - Fork 651
Closed
Description
- Android Studio version:4.2.2
- Firebase Component: Firestore
- Component version: firebase-bom:28.2.0
When trying to write a custom object to the Firestore the error occurs. When trying to write it as a HashMap the request is successful. Using the example from the tutorial
Steps to reproduce:
- define a custom
data class - initialize the object and add a new document to the Firestore
firestore.collections("test").add(user)
Relevant Code:
Custom class
data class User(
val firstName: String? = null,
val lastName: String? = null,
val email: String? = null
){
fun toMap(): HashMap<String, Any?>{
return hashMapOf(
"FirstName" to firstName,
"LastName" to lastName,
"Email" to email
)
}
}
Creating an object
val user = User(
"John",
"Doe",
"john.doe@email.com",
)
ds.createUser(user)
This fails
fun createUser(user: User) {
Log.v(TAG, "createUser")
firestore.collection("test").add(user)
.addOnSuccessListener {
Log.v(TAG, "Writing to database successfull")
}
.addOnFailureListener { e ->
Log.w(TAG, "ERROR: ", e)
}
}
This succeeds
fun createUser(user: User) {
Log.v(TAG, "createUser")
firestore.collection("test").add(user.toMap())
.addOnSuccessListener {
Log.v(TAG, "Writing to database successfull")
}
.addOnFailureListener { e ->
Log.w(TAG, "ERROR: ", e)
}
}