@@ -34,8 +34,15 @@ public static WritableMap convertMapToWritableMap(Map<String, Object> input) {
34
34
Object value = entry .getValue ();
35
35
if (value instanceof Map ) {
36
36
output .putMap (key , convertMapToWritableMap ((Map <String , Object >) value ));
37
- } else if (value instanceof JSONArray ) {
38
- output .putArray (key , convertArrayToWritableArray ((Object []) value ));
37
+ } else if (value instanceof JSONObject ) {
38
+ try {
39
+ output .putMap (key , convertJSONObjectToWritableMap ((JSONObject ) value ));
40
+ } catch (JSONException e ) {
41
+ Log .e (RNBatchModuleImpl .LOGGER_TAG , "Failed to parse JSON Object." , e );
42
+ }
43
+ }
44
+ else if (value instanceof JSONArray ) {
45
+ output .putArray (key , convertArrayToWritableArray ((JSONArray ) value ));
39
46
} else if (value instanceof Boolean ) {
40
47
output .putBoolean (key , (Boolean ) value );
41
48
} else if (value instanceof Integer ) {
@@ -48,36 +55,47 @@ public static WritableMap convertMapToWritableMap(Map<String, Object> input) {
48
55
output .putDouble (key , ((Date ) value ).getTime ());
49
56
} else if (value instanceof URI ) {
50
57
output .putString (key , value .toString ());
58
+ } else if (value == null || value == JSONObject .NULL ) {
59
+ output .putNull (key );
51
60
} else {
52
61
output .putString (key , value .toString ());
53
62
}
54
63
}
55
64
return output ;
56
65
}
57
66
58
- public static WritableArray convertArrayToWritableArray (Object [] input ) {
67
+ public static WritableArray convertArrayToWritableArray (JSONArray input ) {
59
68
WritableArray output = new WritableNativeArray ();
60
69
61
- for (int i = 0 ; i < input .length ; i ++) {
62
- Object value = input [i ];
63
- if (value instanceof Map ) {
64
- output .pushMap (convertMapToWritableMap ((Map <String , Object >) value ));
65
- } else if (value instanceof JSONArray ) {
66
- output .pushArray (convertArrayToWritableArray ((Object []) value ));
67
- } else if (value instanceof Boolean ) {
68
- output .pushBoolean ((Boolean ) value );
69
- } else if (value instanceof Integer ) {
70
- output .pushInt ((Integer ) value );
71
- } else if (value instanceof Double ) {
72
- output .pushDouble ((Double ) value );
73
- } else if (value instanceof String ) {
74
- output .pushString ((String ) value );
75
- } else if (value instanceof Date ) {
76
- output .pushDouble (((Date ) value ).getTime ());
77
- } else if (value instanceof URI ) {
78
- output .pushString (value .toString ());
79
- } else {
80
- output .pushString (value .toString ());
70
+ for (int i = 0 ; i < input .length (); i ++) {
71
+ Object value = null ;
72
+ try {
73
+ value = input .get (i );
74
+ if (value instanceof Map ) {
75
+ output .pushMap (convertMapToWritableMap ((Map <String , Object >) value ));
76
+ }
77
+ else if (value instanceof JSONObject ) {
78
+ output .pushMap (convertJSONObjectToWritableMap ((JSONObject ) value ));
79
+ }
80
+ else if (value instanceof JSONArray ) {
81
+ output .pushArray (convertArrayToWritableArray ((JSONArray ) value ));
82
+ } else if (value instanceof Boolean ) {
83
+ output .pushBoolean ((Boolean ) value );
84
+ } else if (value instanceof Integer ) {
85
+ output .pushInt ((Integer ) value );
86
+ } else if (value instanceof Double ) {
87
+ output .pushDouble ((Double ) value );
88
+ } else if (value instanceof String ) {
89
+ output .pushString ((String ) value );
90
+ } else if (value instanceof Date ) {
91
+ output .pushDouble (((Date ) value ).getTime ());
92
+ } else if (value instanceof URI ) {
93
+ output .pushString (value .toString ());
94
+ } else {
95
+ output .pushString (value .toString ());
96
+ }
97
+ } catch (JSONException e ) {
98
+ Log .e (RNBatchModuleImpl .LOGGER_TAG , "Failed to parse JSON Array." , e );
81
99
}
82
100
}
83
101
return output ;
@@ -163,7 +181,6 @@ public static WritableMap convertJSONObjectToWritableMap(JSONObject jsonObject)
163
181
Object value = jsonObject .get (key );
164
182
map .put (key , value );
165
183
}
166
-
167
184
return convertMapToWritableMap (map );
168
185
}
169
186
}
0 commit comments