When calling
FirebaseFirestore.getInstance().collection("myCollection").document("doc1").update("field1",myObject);
I get the error:
IllegalArgumentException: Invalid data. Unsupported type: com.myProg.objects.MyObject (found in field field1)
Even though I can add myObject to firestore when it is part of myDoc using Set method without a problem.
MyObject class (The simplest example):
public class MyObject{
public int i;
}
Edit: my DB Structure before attempting:
myCollection ->
doc1: field0 - "3" field1 - null
also tried it without field1
So the only way, to update as of now is by using a map. In your case it should look like
Map<String, Object> updateMap = new HashMap();
updateMap.put("field1.i", myObject.i);
FirebaseFirestore.getInstance().collection("myCollection")
.document("doc1").update(updateMap);
I think Firestore should really update the APIs to facilitate updating of nested objects as a whole.
In my case i wanted to update the complex object in the firestore.
public class UserInitialModel {
private List<ServiceItemModel> servicesOffered;
}
public class ServiceItemModel{
private String serviceName;
private String price;
}
it was giving me error when i try to update java.lang.IllegalArgumentException: Invalid data. Unsupported type:
I Solved it by by using map
List<Map<String,Object>> list=new ArrayList<>();
for (ServiceItemModel model:
mUserInitialPresenter.getUserInitialModel().getServicesOffered()) {
Map<String,Object> servicesOffered=new HashMap<>();
servicesOffered.put("serviceName",model.getServiceName());
servicesOffered.put("price",model.getPrice());
list.add(servicesOffered);
}
dataMap.put("servicesOffered",list);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With