JsonUtils { public Object expand(Object input) { if (input instanceof List) { expandList((List<Object>) input); return input; } else if (input instanceof Map) { expandMap((Map<String, Object>) input); return input; } else if (input instanceof String) { return getJson((String) input); } else { return input; } } JsonUtils(); Object expand(Object input);  }
@Test public void testArray() { List<Object> list = new LinkedList<>(); Map<String, Object> map = new HashMap<>(); map.put("externalId", "[{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}]"); map.put("name", "conductor"); map.put("version", 2); list.add(map); map = (Map<String, Object>) list.get(0); assertTrue(map.get("externalId") instanceof String); int before = list.size(); jsonUtils.expand(list); assertEquals(before, list.size()); map = (Map<String, Object>) list.get(0); assertTrue(map.get("externalId") instanceof ArrayList); }
@Test public void testMap() { Map<String, Object> map = new HashMap<>(); map.put("externalId", "{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}"); map.put("name", "conductor"); map.put("version", 2); assertTrue(map.get("externalId") instanceof String); jsonUtils.expand(map); assertTrue(map.get("externalId") instanceof LinkedHashMap); }
@Test public void testMultiLevelMap() { Map<String, Object> parentMap = new HashMap<>(); parentMap.put("requestId", "abcde"); parentMap.put("status", "PROCESSED"); Map<String, Object> childMap = new HashMap<>(); childMap.put("path", "test/path"); childMap.put("type", "VIDEO"); Map<String, Object> grandChildMap = new HashMap<>(); grandChildMap.put("duration", "370"); grandChildMap.put("passed", "true"); childMap.put("metadata", grandChildMap); parentMap.put("asset", childMap); Object jsonObject = jsonUtils.expand(parentMap); assertNotNull(jsonObject); }