Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin class does not get its boolean value from firebase

I have my kotlin class as

class Center : Serializable {
var active: Boolean? = null
var address: String? = null
var isJobAccessGranted: Boolean? = null
}

here is how i am getting value

 //from java class
   @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
            centerMap.put(dataSnapshot.getKey(), dataSnapshot.getValue(Center.class));
        }

but problem is that i am getting value of active field without any issue. But isJobAccessGranted boolean field always remains null. I have tested with some other boolean removing is prefix which works fine. I don't get Boolean value when i use isActive or isJobAccessGranted. Can anyone explain me why i am facing this issue. #AskFirebase

like image 921
FaisalAhmed Avatar asked Sep 25 '17 13:09

FaisalAhmed


1 Answers

As mentioned in comment in Kotlin you should add @field:JvmField for every Boolean field in class, as when Kotlin translates to Java it generates setters, which names couldnt be resolved by JSON parser. And @field:JvmField annotation overrides this feature and there will be correct setters names and JSON will be parsed correctly.

like image 73
mohax Avatar answered Sep 29 '22 01:09

mohax