【发布时间】:2018-05-16 11:03:09
【问题描述】:
我想将 firebase firestore 中的数据反序列化为模型 (Foo)
data class Foo(
var timestamp: Int = 0,
var title: String = "",
var question: String = "",
var category: String = "",
var content: String = "",
var link: String = ""
) {
fun Foo() {}
}
这样的查询:
FirebaseFirestore.getInstance().collection(COLLECTION_NAME)
.orderBy(ORDER_KEY, Query.Direction.DESCENDING)
.limit(LIMIT)
.get()
.addOnSuccessListener { snapshot ->
snapshot.documents.forEach {
println(it.data) // data print successfully
// got error java.lang.RuntimeException: Could not deserialize object. Failed to convert a value of type com.google.firebase.firestore.Blob to int (found in field 'timestamp')
val foo = it.toObject(Foo::class.java)
}
}
但出现错误java.lang.RuntimeException: Could not deserialize object. Failed to convert a value of type com.google.firebase.firestore.Blob to int (found in field 'timestamp')
我在我的 android 项目中使用 firebase 版本 11.6.2
firestore 中的数据在此屏幕截图中的位置:
知道反序列化失败的原因吗?
【问题讨论】:
-
println(it.data)打印什么? -
感谢您检查打印数据后,我发现了一个无效数据,其中
{timestamp=blob, title=blob, category=blob...}其他数据正常``{timestamp=1135129980, title=jkjk, category=xys..}`
标签: android firebase kotlin google-cloud-firestore