[firestore][android] Correctly deserialise firestore arrays

This commit is contained in:
Chris Bianca 2017-10-04 18:58:48 +01:00
parent aca519a47d
commit 5d6f43a540
2 changed files with 4 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot; import com.google.firebase.firestore.QuerySnapshot;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -146,7 +147,7 @@ public class FirestoreSerialize {
writableArray.pushMap((objectMapToWritable((Map<String, Object>) item))); writableArray.pushMap((objectMapToWritable((Map<String, Object>) item)));
} else if (itemClass == Arrays.class) { } else if (itemClass == Arrays.class) {
writableArray.pushArray(objectArrayToWritable((Object[]) item)); writableArray.pushArray(objectArrayToWritable((Object[]) item));
} else if (itemClass == List.class) { } else if (itemClass == List.class || itemClass == ArrayList.class) {
List<Object> list = (List<Object>) item; List<Object> list = (List<Object>) item;
Object[] listAsArray = list.toArray(new Object[list.size()]); Object[] listAsArray = list.toArray(new Object[list.size()]);
writableArray.pushArray(objectArrayToWritable(listAsArray)); writableArray.pushArray(objectArrayToWritable(listAsArray));
@ -185,7 +186,7 @@ public class FirestoreSerialize {
map.putMap(key, (objectMapToWritable((Map<String, Object>) value))); map.putMap(key, (objectMapToWritable((Map<String, Object>) value)));
} else if (valueClass == Arrays.class) { } else if (valueClass == Arrays.class) {
map.putArray(key, objectArrayToWritable((Object[]) value)); map.putArray(key, objectArrayToWritable((Object[]) value));
} else if (valueClass == List.class) { } else if (valueClass == List.class || valueClass == ArrayList.class) {
List<Object> list = (List<Object>) value; List<Object> list = (List<Object>) value;
Object[] array = list.toArray(new Object[list.size()]); Object[] array = list.toArray(new Object[list.size()]);
map.putArray(key, objectArrayToWritable(array)); map.putArray(key, objectArrayToWritable(array));

View File

@ -249,7 +249,7 @@ function collectionReferenceTests({ describe, it, context, firebase }) {
it('should create Document', () => { it('should create Document', () => {
return firebase.native.firestore() return firebase.native.firestore()
.doc('document-tests/doc2') .doc('document-tests/doc2')
.set({ name: 'doc2' }) .set({ name: 'doc2', testArray: [] })
.then(async () => { .then(async () => {
const doc = await firebase.native.firestore().doc('document-tests/doc2').get(); const doc = await firebase.native.firestore().doc('document-tests/doc2').get();
doc.data().name.should.equal('doc2'); doc.data().name.should.equal('doc2');