static HashMap<String, Object> toHashMap(ReadableMap map) {
HashMap<String, Object> hashMap = new HashMap<>();
ReadableMapKeySetIterator iterator = map.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
switch (map.getType(key)) {
case Null:
hashMap.put(key, null);
break;
case Boolean:
hashMap.put(key, map.getBoolean(key));
break;
case Number:
hashMap.put(key, map.getDouble(key));
break;
case String:
hashMap.put(key, map.getString(key));
break;
case Map:
hashMap.put(key,toHashMap(map.getMap(key)));
break;
case Array:
hashMap.put(key, toArrayList(map.getArray(key)));
break;
default:
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
}
}
return hashMap;
}