Firestore更新失败,出现IllegalArgumentException:数据无效.不支持的类型

Cap*_*emo 7 android firebase firebase-security google-cloud-firestore

打电话的时候

FirebaseFirestore.getInstance().collection("myCollection").document("doc1").update("field1",myObject);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

IllegalArgumentException:无效的数据.不支持的类型:com.myProg.objects.MyObject(在字段field1中找到)

尽管我可以使用Set方法将myObject添加到firestore,而不是使用Set方法.

MyObject类(最简单的例子):

public class MyObject{
   public int i;
}
Run Code Online (Sandbox Code Playgroud)

在尝试之前编辑:我的数据库结构:

myCollection - >

doc1:

field0 - "3"

field1 - null
Run Code Online (Sandbox Code Playgroud)

也试过没有field1

Deb*_*jan 11

因此,现在更新的唯一方法是使用地图.在你的情况下它应该看起来像

Map<String, Object> updateMap = new HashMap();
updateMap.put("field1.i", myObject.i);

FirebaseFirestore.getInstance().collection("myCollection")
.document("doc1").update(updateMap);
Run Code Online (Sandbox Code Playgroud)

我认为Firestore应该真正更新API以便于整体嵌套对象的更新.