我试图在Firestore中读取一个集合。为此,我想将相应的文档转换到我的POJO类中。但是,我得到了下面列出的错误
我的数据类模型:
data class NewObjektPojo(
val objektHauptBild: String? = "",
val objektName: String? = "",
val objektBeschreibung: String? = "",
val objektBilder: MutableList<String>? = null,
val objektZimmer: Number? = 0,
val objektGroeße: Number? = 0,
val objektPreis: Number? = 0,
val objektLatitude: Double? = null,
val objektLontitude: Double? = null,
)
抛出错误的部分:
db.collectionGroup("Houses").get().addOnSuccessListener { snapshot ->
for(document in snapshot.documents)
{
//mistake happens here
val house = document.toObject(NewObjektPojo::class.java)
objektListe.add(house!!)
}
}
java.lang.RuntimeException:无法反序列化对象。不支持将值反序列化为Number(在字段"objektGroeße"中找到)
类型应适合:
1条答案
按热度按时间t2a7ltrp1#
出现此错误是因为
Number
不是数据类型。请为这些变量使用Long
数据类型更换这些
有了这些