diff --git a/android/src/main/java/com/emarsys/rnwrapper/ArrayUtil.java b/android/src/main/java/com/emarsys/rnwrapper/ArrayUtil.java index b5f40f7..084552b 100644 --- a/android/src/main/java/com/emarsys/rnwrapper/ArrayUtil.java +++ b/android/src/main/java/com/emarsys/rnwrapper/ArrayUtil.java @@ -10,6 +10,7 @@ import org.json.JSONException; import org.json.JSONObject; +import java.util.ArrayList; import java.util.Map; public class ArrayUtil { @@ -122,6 +123,32 @@ public static WritableArray toWritableArray(Object[] array) { return writableArray; } + public static WritableArray arrayListToWritableArray(ArrayList array) { + WritableArray writableArray = Arguments.createArray(); + + for (int i = 0; i < array.size(); i++) { + Object value = array.get(i); + + if (value == null) { + writableArray.pushNull(); + } else if (value instanceof Boolean) { + writableArray.pushBoolean((Boolean) value); + } else if (value instanceof Double) { + writableArray.pushDouble((Double) value); + } else if (value instanceof Integer) { + writableArray.pushInt((Integer) value); + } else if (value instanceof String) { + writableArray.pushString((String) value); + } else if (value instanceof Map) { + writableArray.pushMap(MapUtil.toWritableMap((Map) value)); + } else if (value instanceof ArrayList) { + writableArray.pushArray(ArrayUtil.arrayListToWritableArray((ArrayList) value)); + } + } + + return writableArray; + } + public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { WritableArray writableArray = new WritableNativeArray(); diff --git a/android/src/main/java/com/emarsys/rnwrapper/MapUtil.java b/android/src/main/java/com/emarsys/rnwrapper/MapUtil.java index 0e871e7..22059f9 100644 --- a/android/src/main/java/com/emarsys/rnwrapper/MapUtil.java +++ b/android/src/main/java/com/emarsys/rnwrapper/MapUtil.java @@ -12,6 +12,7 @@ import org.json.JSONObject; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -125,6 +126,8 @@ public static WritableMap toWritableMap(Map map) { writableMap.putString((String) pair.getKey(), (String) value); } else if (value instanceof Map) { writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map) value)); + } else if (value instanceof ArrayList) { + writableMap.putArray((String) pair.getKey(), ArrayUtil.arrayListToWritableArray((ArrayList) value)); } else if (value.getClass() != null && value.getClass().isArray()) { writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value)); }