firestore android 在保存时在自定义 Parcelable 类中添加“稳定性”字段

firestore android adding "stability" field in custom Parcelable class while saving

提问人:BalaramNayak 提问时间:7/12/2023 更新时间:11/8/2023 访问量:255

问:

我有一个可打包的类 Image

@Parcelize
data class Image(val id:String="",val url:String=""):Parcelable

并用于保存在 Firestore 中

val data = HashMap<String,Any>()
data["title"] = "My Title"
data["image] = Image("dgdg1","https://someimagepath")
firestore.collection("collectionname").document(documentId).set(data,SetOptions.merge()).await()

数据正在保存在Firestore中,但在“图像”中,它添加了一个额外的字段“稳定性”。输出结果是这样的

{  
  "title":"My Title",  
  "image":{
    "stability":0,
    "id":"dgdg1",
    "url":"https://someimagepath"
  } 
}

为什么这个“稳定性”会自动添加到图像对象中。

Android Firebase Kotlin Google-Cloud-Firestore 可包

评论

0赞 Alex Mamo 7/13/2023
你找到问题了吗?
2赞 BalaramNayak 7/14/2023
是的,在序列化 Firebase 时,使用 CustomClassMapper 类。serialize 函数采用所有类级字段、getter 及其 Parent 类 getter 和字段。在本例中,Parcelabe 是具有名为 getStability() 的 getter 方法的父类。因此,在序列化时,它包括稳定性字段。

答:

0赞 3 revs, 3 users 86%Robert G #1

根据 @BalaramNayak 的评论

序列化 Firebase 使用该类。该函数采用所有类级字段、getter 及其 Parent 类和字段。在本例中,是具有名为 的 getter 方法的父类。因此,在序列化时,它包括字段。CustomClassMapperserializegettersParcelablegetStability()stability

有关其他信息,请参阅以下文档: