0

I have a parcelable class Image

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

and for saving in 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()

data is getting saved in firestore but inside the "image" it is adding an extra field "stability" . The out put result is like this

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

why is this "stability" is automatically added to the image object.

BalaramNayak
  • 1,295
  • 13
  • 16
  • Have you found the issue? – Alex Mamo Jul 13 '23 at 06:14
  • Yes, while serializing Firebase Uses CustomClassMapper class. The serialize function takes all class-level fields, getters, and its Parent class getters and fields. In this case, Parcelabe is the parent class with a getter method named getStability(). So while serializing it includes the stability field. – BalaramNayak Jul 14 '23 at 08:02

1 Answers1

1

Posting as a community wiki for visibility.


As per @BalaramNayak's comment:

Serializing Firebase uses the CustomClassMapper class. The serialize function takes all class-level fields, getters, and its Parent class getters and fields. In this case, Parcelable is the parent class with a getter method named getStability(). So while serializing it includes the stability field.

You may refer to the documentations below for additional information:

Hope this helps.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Robert G
  • 1,583
  • 3
  • 13