Read data from the given JSONObject and populate the given Map @param json_object @param map @param inner_classes @throws Exception
(
final JSONObject json_object, final Map map, final Stack<Class> inner_classes)
| 323 | * @throws Exception |
| 324 | */ |
| 325 | @SuppressWarnings({"unchecked", "rawtypes"}) |
| 326 | protected static void readMapField( |
| 327 | final JSONObject json_object, final Map map, final Stack<Class> inner_classes) |
| 328 | throws Exception { |
| 329 | Class<?> key_class = inner_classes.pop(); |
| 330 | Class<?> val_class = inner_classes.pop(); |
| 331 | Collection<Class<?>> val_interfaces = ClassUtil.getInterfaces(val_class); |
| 332 | |
| 333 | for (String json_key : CollectionUtil.iterable(json_object.keys())) { |
| 334 | final Stack<Class> next_inner_classes = new Stack<>(); |
| 335 | next_inner_classes.addAll(inner_classes); |
| 336 | |
| 337 | // KEY |
| 338 | Object key = JSONUtil.getPrimitiveValue(json_key, key_class); |
| 339 | |
| 340 | // VALUE |
| 341 | Object object = null; |
| 342 | if (json_object.isNull(json_key)) { |
| 343 | // Nothing... |
| 344 | } else if (val_interfaces.contains(List.class)) { |
| 345 | object = new ArrayList(); |
| 346 | readCollectionField( |
| 347 | json_object.getJSONArray(json_key), (Collection) object, next_inner_classes); |
| 348 | } else if (val_interfaces.contains(Set.class)) { |
| 349 | object = new HashSet(); |
| 350 | readCollectionField( |
| 351 | json_object.getJSONArray(json_key), (Collection) object, next_inner_classes); |
| 352 | } else if (val_interfaces.contains(Map.class)) { |
| 353 | object = new HashMap(); |
| 354 | readMapField(json_object.getJSONObject(json_key), (Map) object, next_inner_classes); |
| 355 | } else { |
| 356 | String json_string = json_object.getString(json_key); |
| 357 | |
| 358 | object = JSONUtil.getPrimitiveValue(json_string, val_class); |
| 359 | } |
| 360 | map.put(key, object); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Read data from the given JSONArray and populate the given Collection |
no test coverage detected