ClassMapper: No setter/field for aBooleanType

Viewed 963

I am using firebase and this is my data class definition:

data class ClaimOrder(val address: String? = null,
                  val amount: Long = 0L,
                  val isProcessed: Boolean = false,
                  val onCreate: kotlin.Any? = ServerValue.TIMESTAMP)

however on logs I am seeing following warning: W/ClassMapper: No setter/field for isProcessed found on class com.guness.bitfarm.service.models.ClaimOrder

I have tried @SerializedName("isProcessed") but no luck.

3 Answers

For some reason even if I left out the is in front of the variable name it still wouldn't parse. Instead I solved it by just making a custom constructor like so:

data class User(
    var uid: String? = null,
    var isDeveloper: Boolean? = null,
    var email: String? = null
) {
    constructor(dict: Map<String, Any>) : this() {
        this.uid = dict["uid"] as? String
        this.isDeveloper = dict["isDeveloper"] as? Boolean
        this.email = dict["email"] as? String
    }
}

Which I parsed like so:

documentSnapshot.data?.let {
    completion(User(it), null)
    return@addOnSuccessListener
}

Although it's probably not the best solution if you need a massive constructor but for small data classes it works fine :)

Related