Android Firestore-数组中的更新对象导致不支持的类型
我对使用新的firestore功能感到困惑 在firestore文档中,我有一个带有自定义对象“MyObect”的数组“List” 工作正常,如预期 但当我尝试这个:Android Firestore-数组中的更新对象导致不支持的类型,android,arrays,google-cloud-firestore,Android,Arrays,Google Cloud Firestore,我对使用新的firestore功能感到困惑 在firestore文档中,我有一个带有自定义对象“MyObect”的数组“List” 工作正常,如预期 但当我尝试这个: MyObject object = new MyObject(Value1, Value2); ...update("List", FieldValue.arrayUnion(object)); 我以错误告终 java.lang.IllegalArgumentException: Invalid data. Unsup
MyObject object = new MyObject(Value1, Value2);
...update("List", FieldValue.arrayUnion(object));
我以错误告终
java.lang.IllegalArgumentException: Invalid data. Unsupported type: com.my.app.MyObject
at com.google.firebase.firestore.core.UserData$ParseContext.createError(com.google.firebase:firebase-firestore@@17.1.3:293)
at com.google.firebase.firestore.UserDataConverter.parseScalarValue(com.google.firebase:firebase-firestore@@17.1.3:405)
at com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:firebase-firestore@@17.1.3:254)
at com.google.firebase.firestore.UserDataConverter.parseArrayTransformElements(com.google.firebase:firebase-firestore@@17.1.3:419)
at com.google.firebase.firestore.UserDataConverter.parseSentinelFieldValue(com.google.firebase:firebase-firestore@@17.1.3:335)
at com.google.firebase.firestore.UserDataConverter.parseData(com.google.firebase:firebase-firestore@@17.1.3:237)
at com.google.firebase.firestore.UserDataConverter.parseUpdateData(com.google.firebase:firebase-firestore@@17.1.3:171)
at com.google.firebase.firestore.DocumentReference.update(com.google.firebase:firebase-firestore@@17.1.3:239)
编辑
以下是我的数据库结构:
/UserData/UserID/Data/DataSet01/
在此路径下,我有几个值,如:
- 名字
- 出生
- 性别
- 列表(数组)
DocumentReference document= FirebaseFirestore.getInstance().document("UserData").collection("UserID").document("DataSet01");
document.update("List", FieldValue.arrayUnion(myObject));
我也遇到了同样的问题,发现使用自定义对象是行不通的。 所以我尝试了
HashMap
I Kotlin
val myObject = HashMap<String,Any>()
myObject["Value1"]="Some Value"
myObject["Value2"]="Some other Value"
document.update("List", FieldValue.arrayUnion(myObject))
val myObject=HashMap()
myObject[“值1”]=“某些值”
myObject[“Value2”]=“其他值”
文档更新(“列表”,FieldValue.arrayUnion(myObject))
在Java中
HashMap<String, String> myObject = new HashMap<String, String>();
myObject.put("Value1","Some Value");
myObject.put("Value1","Some Other Value");
document.update("List", FieldValue.arrayUnion(myObject));
HashMap myObject=newhashmap();
myObject.put(“值1”、“某些值”);
myObject.put(“值1”、“其他值”);
文件更新(“列表”,FieldValue.arrayUnion(myObject));
希望有帮助:)请添加您的数据库结构以查看您的
TestArray
以及您的列表
数组。然后我们如何才能将该字段作为arraylist获取?Genius。工作得很有魅力。
val myObject = HashMap<String,Any>()
myObject["Value1"]="Some Value"
myObject["Value2"]="Some other Value"
document.update("List", FieldValue.arrayUnion(myObject))
HashMap<String, String> myObject = new HashMap<String, String>();
myObject.put("Value1","Some Value");
myObject.put("Value1","Some Other Value");
document.update("List", FieldValue.arrayUnion(myObject));