ParseDecoder { List<Object> convertJSONArrayToList(JSONArray array) { List<Object> list = new ArrayList<>(); for (int i = 0; i < array.length(); ++i) { list.add(decode(array.opt(i))); } return list; } protected  ParseDecoder(); static ParseDecoder get(); Object decode(Object object);  }
@Test public void testConvertJSONArrayToList() { JSONArray jsonArray = new JSONArray(); jsonArray.put("Object1"); JSONArray internalJSONArray = new JSONArray(); internalJSONArray.put("Object2.1"); internalJSONArray.put("Object2.2"); jsonArray.put(internalJSONArray); List<Object> objects = ParseDecoder.get().convertJSONArrayToList(jsonArray); assertNotNull(objects); assertEquals(2, objects.size()); assertEquals("Object1", objects.get(0)); List<String> subObjects = (List<String>) objects.get(1); assertNotNull(subObjects); assertEquals(2, subObjects.size()); assertEquals("Object2.1", subObjects.get(0)); assertEquals("Object2.2", subObjects.get(1)); }