Skip to content Skip to sidebar Skip to footer

Firebase Firestore Toobject() Not Working With Data Class

I want to get data from firebase firestore and convert toObject() with a data class. But it does not work as the object gets initialized but the field is not set. This is very simi

Solution 1:

I was facing a similar problem with the same error message (No setter/field ...) and I solved this by adding get/set annotations in the data class, ie:

dataclassUser(
    @get: PropertyName("first_name") @set: PropertyName("first_name") var firstName: String = "",
    @get: PropertyName("last_name") @set: PropertyName("last_name") var lastName: String = "",
    @get: PropertyName("email") @set: PropertyName("email") var email: String = ""
)

And then converted to object like this:

val user: User? = documentSnapshot.toObject(User::class.java)

Post a Comment for "Firebase Firestore Toobject() Not Working With Data Class"