【发布时间】:2020-04-06 07:00:53
【问题描述】:
data class CancerBiomarker (
val type : String?= null,
val biomarkers : List<Biomarkers> = emptyList()
)
data class Biomarkers(
val title: String? = null,
val content: Biomarker? = null
)
data class Biomarker (
val content:String? = null
)
这是我的数据类。在该内容被声明为 Reference.After 运行后,我得到以下异常,如果我将内容更改为 DocumentReference,那么我也会得到异常
java.lang.RuntimeException: Could not deserialize object. Can't convert object of type com.google.firebase.firestore.DocumentReference to type com.firestorepoc.model.Biomarker
如何将引用映射到 POJO 模型?
val firebaseFirestore: FirebaseFirestore = FirebaseFirestore.getInstance()
firebaseFirestore.collection("CancerBiomarker")
.get()
.addOnCompleteListener(OnCompleteListener<QuerySnapshot> { task ->
if (task.isSuccessful) {
val result : MutableList<CancerBiomarker>? = task.result?.toObjects(CancerBiomarker::class.java)
} else {
Log.w("Document", "Document " + "Error getting documents.", task.exception)
}
})
【问题讨论】:
-
请编辑问题以显示您要映射的文档的确切数据。如果类型不匹配,您将收到该错误。该消息表明您在内容字段中存储了一个字符串,而不是一个引用。
标签: android firebase kotlin google-cloud-firestore