Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassMapper: No setter/field for aBooleanType

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.

like image 768
guness Avatar asked Aug 16 '17 17:08

guness


2 Answers

I can't find any official document from Firebase mentioning about the naming rules of the getter and setter, but it seems like they are looking for JavaBean-like getters/setters

When you have a property named isProcessed, Firebase requires you to have getter/setter named getIsProcessed()/setIsProcessed(). However, a different naming rule is applied when the property is start with is in Kotlin. It genarates getter/setter named isProcessed()/setProcessed(), according to Kotlin doc:

If the name of the property starts with is, a different name mapping rule is used: the name of the getter will be the same as the property name, and the name of the setter will be obtained by replacing is with set. For example, for a property isOpen, the getter will be called isOpen() and the setter will be called setOpen(). This rule applies for properties of any type, not just Boolean.

like image 134
BakaWaii Avatar answered Sep 29 '22 01:09

BakaWaii


I don't know the exact reason but here is my guess:

variable name isProcessed causes different accessor methods to be generated so underlying gson and kotlin methods does not match.

however using just processed seems to fix things well.

like image 22
guness Avatar answered Sep 29 '22 01:09

guness