I have nested objects in Firestore where I have the document tied to the logged in user's UUID.
I am able to get the nested values out by converting to a Map and calling getData on the DocumentSnapshot. Then looping over the Map entry set. I have typically used Firestore's methods to convert the result back over to my custom object (e.g. documentSnapshot.toObject(POJO.class) and throw them in a list, but since I am getting the nested values as a Map, will I need to use something like Jackson or GSON? Once this loop is done, I want to convert to POJO and add each to the arraylist, in this case allVehices.
public ArrayList<Vehicle> getAllVehicles() {
FirebaseFirestore.getInstance().collection("vehicles")
//.whereEqualTo("vehicleUUID",FirebaseAuth.getInstance().getCurrentUser().getUid())
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot documentSnapshot : task.getResult()) {
Map<String,Object> map = (Map<String,Object>) documentSnapshot.getData();
for (Map.Entry<String,Object> entry : map.entrySet()) {
System.out.print(entry.getKey() + "/" + entry.getValue());
}
}
}
}
});
return allVehicles;
}