How to initialize default values for GeoPoint in a data class

前端 未结 1 787
一整个雨季
一整个雨季 2021-01-27 07:25

I\'m trying to convert documents to objects from Firestore, but when I create my data class , I dont know how to initialize the GeoPoint with default values as it needs to be de

相关标签:
1条回答
  • 2021-01-27 08:20

    The problem is that the Firestore SDK isn't finding a default, no argument constructor for MapObj. Kotlin data classes don't have one if all of their properties are declared with val. For properties declared val, Kotlin requires that their values be specified in the constructor, since they can't possibly change afterward.

    If you must get a data class back from Firestore, you will have to make all of its properties optional var with a default value, so that Kotlin will generate a no-arg constructor for it.

    data class MapObj(var geopoint: Geopoint? = null)
    
    0 讨论(0)
提交回复
热议问题