Hi I have 2 arrays like phonenumber[1,2,3] amount[10,20,30] I need to store the data in a single document like field1: 1 field2: 10
The code I tried is
I took the object like **
public class Pojo {
String invitee;
Map<Integer,Integer>phoneAmount;
public Pojo(String invitee, Map<Integer, Integer> phoneAmount)
{
this.invitee = invitee;
this.phoneAmount=phoneAmount;
}
}**
And in another class
Map<int[], int[]> phoneAmount = new HashMap<>();
phoneAmount.put(phonenumber,amount);
db.collection("Split").document("invitees").set(phoneAmount).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "DocumentSnapshot successfully written!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error writing document", e);
}
});
It shows error like java.lang.RuntimeException: Could not serialize object. Maps with non-string keys are not supported at com.google.android.gms.internal.zzejw.zza(Unknown Source) at com.google.android.gms.internal.zzejw.zza(Unknown Source) at com.google.android.gms.internal.zzejw.zzbp(Unknown Source)
String fieldand oneMap<int,int> phoneAmountand a constructorpublic YourPojoClass(String title, Map<int,int> phoneAmount ). By this you can add items tophoneAmountobject likephoneAmount.put(phoneNumber, amount);and then add document to collection reference likedb.collection("Split").document("lahari").set(yourPojoClass)after creating object of your PojoClass likeMyPojo pojo= new MyPojo ("invite", phoneAmount );