@Test public void jsonArrayToList_forSimpleList_returnsExpectedList() { List<Object> expectedList = new ArrayList<>(); expectedList.add(1); expectedList.add(2); expectedList.add(3); expectedList.add("a"); expectedList.add(true); expectedList.add("cde"); try { JSONArray testJsonArray = new JSONArray(SIMPLE_JSON_TEST_ARRAY); List<Object> convertedJsonArray = StripeJsonUtils.jsonArrayToList(testJsonArray); JsonTestUtils.assertListEquals(expectedList, convertedJsonArray); } catch (JSONException jsonException) { fail("Test data failure " + jsonException.getLocalizedMessage()); } }
@Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList.add(jsonArrayToList((JSONArray) ob)); } else if (ob instanceof JSONObject) { Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob); if (objectMap != null) { objectList.add(objectMap); } } else { if (NULL.equals(ob)) { continue; } objectList.add(ob); } } catch (JSONException ignored) { } } return objectList; }
StripeJsonUtils { @Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList.add(jsonArrayToList((JSONArray) ob)); } else if (ob instanceof JSONObject) { Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob); if (objectMap != null) { objectList.add(objectMap); } } else { if (NULL.equals(ob)) { continue; } objectList.add(ob); } } catch (JSONException ignored) { } } return objectList; } }
StripeJsonUtils { @Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList.add(jsonArrayToList((JSONArray) ob)); } else if (ob instanceof JSONObject) { Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob); if (objectMap != null) { objectList.add(objectMap); } } else { if (NULL.equals(ob)) { continue; } objectList.add(ob); } } catch (JSONException ignored) { } } return objectList; }  }
StripeJsonUtils { @Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList.add(jsonArrayToList((JSONArray) ob)); } else if (ob instanceof JSONObject) { Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob); if (objectMap != null) { objectList.add(objectMap); } } else { if (NULL.equals(ob)) { continue; } objectList.add(ob); } } catch (JSONException ignored) { } } return objectList; }   }
StripeJsonUtils { @Nullable static List<Object> jsonArrayToList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } List<Object> objectList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { try { Object ob = jsonArray.get(i); if (ob instanceof JSONArray) { objectList.add(jsonArrayToList((JSONArray) ob)); } else if (ob instanceof JSONObject) { Map<String, Object> objectMap = jsonObjectToMap((JSONObject) ob); if (objectMap != null) { objectList.add(objectMap); } } else { if (NULL.equals(ob)) { continue; } objectList.add(ob); } } catch (JSONException ignored) { } } return objectList; }    }