17

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

FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76
  • 1
    you have a property called isJobAccessGranted, so appropriate generated getter will be isIsJobAccessGranted. Maybe it is the issue? – Mike Sep 25 '17 at 13:42
  • no @mike it is not generating isIsJobAccessGranted – FaisalAhmed Sep 25 '17 at 13:55
  • 8
    Dont know the exact reason behind this but using `@field:JvmField` over `var isJobAccessGranted: Boolean? = null` solved my problem – FaisalAhmed Sep 25 '17 at 15:22

1 Answers1

26

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.

mohax
  • 4,435
  • 2
  • 38
  • 85