Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to add downloadUri to firestore document. "Could not serialize object. Exceeded maximum depth of 500"

I have a Firestore collection in which each document has an image associated with it that is stored in Firebase storage. Previously I stored the image reference and retrieved the image through that, but since that was taking some time for each call, I tried to switch to storing the downloaduri so that with picasso I could reference it through the downloaduri without having to retrieve the downloaduri each item. However when I try to write to the document inside the on success listener of the getdownloaduri, I get an error indicating an object cycle.

If I don't include the update to the database, the code is able to succesfully retrieve the downloaduri and pass it to the recyclerview and display the image, it is only when trying to upload it to the database that I get this error. I've tried updating the database outside of the dowonloadUri.addonsuccesslistenr, however the values I set inside the listener are never updated outside of the listener.

 if(menucarditem.dluri == null)
                        {
                            val storageRef = storage.reference
                            val pathReference = storageRef.child(menucarditem.img)
                            pathReference.downloadUrl.addOnSuccessListener {
                                menucarditem.dluri = it
                                dbMealItem.dluri = it
                                db.collection("menuitems").document(dbMealItem.CatererId + dbMealItem.name).set(dbMealItem).addOnSuccessListener {  }
                                    .addOnFailureListener { }

                           viewAdapter.notifyDataSetChanged()

                            }
       .addOnFailureListener{
                                    Toast.makeText(this, "Image from database not found", Toast.LENGTH_LONG).show()
                                    Log.w(TAG, "Error getting documents: ", it)
                                }
}

The error that is outputted during runtime is:

E/AndroidRuntime: java.lang.IllegalArgumentException: Could not serialize object. Exceeded maximum depth of 500, which likely indicates there's an object cycle (found in field 'dluri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonicalUri.canonica

etc.

like image 808
ChristianK Avatar asked May 14 '19 20:05

ChristianK


1 Answers

The problem is in data type Uri downloadUri = task.getResult(); return uri. But may be in firestore DB require string. So, before you update to firestore change downloadUri to string:

Uri downloadUri = task.getResult();
String uri = downloadUri.toString();
db.collection("menuitems").document(dbMealItem.CatererId + dbMealItem.name).set(**uri**);
like image 156
Latief Anwar Avatar answered Nov 13 '22 01:11

Latief Anwar