Geo-FireStore-Query icon indicating copy to clipboard operation
Geo-FireStore-Query copied to clipboard

Convert addedOrModifiedList to Java Object

Open Tonnie-Dev opened this issue 5 years ago • 1 comments

@chintan369 Thanks lots for this library. I managed to get addedOrModifiedDataList, which fell within distance and given query. However, I am not able to read the object and use it.

This is what I am getting on the log.

[DocumentSnapshot{key=UserPujLocation/Punjabi, metadata=SnapshotMetadata{hasPendingWrites=false, isFromCache=true}, doc=Document{key=UserPujLocation/Punjabi, data=com.google.firebase.firestore.model.ObjectValue@90f60cb1, version=SnapshotVersion(seconds=1599923161, nanos=519260000), documentState=COMMITTED_MUTATIONS}}]

How do I make use of this object?

Tonnie-Dev avatar Sep 12 '20 16:09 Tonnie-Dev

@Fanadezz , I'm happy you found this library useful for you.

If you're using kotlin, then it's very easy to convert this list into your model type class.

val itemList: MutableList<T> = mutableListOf()
//T is type of class or java object in which you want to convert data

geoQuery.get()
	.addOnCompleteListener { firebaseFirestoreException, addedOrModifiedDataList, removedList  ->
		...
		addedOrModifiedDataList.forEach { item ->
                    val objectT = item.toObject(T::class.java)
                    val idOfObjectInFirestore - item.id
                    //you can add this objectT in itemList or can use as your requirement
                }
                ...
	}

chintan369 avatar Sep 13 '20 18:09 chintan369