Utils { @SuppressWarnings("unchecked") public static Object constructRefs(Bridge bridge, Map<String, Object> theMap) { Object pathchain; if ((pathchain = theMap.get("ref")) != null) { return new Reference(bridge, (List<String>) pathchain, (List<String>) theMap.get("operations")); } for (Map.Entry<String, Object> entry : (theMap).entrySet()) { Object value = entry.getValue(); if (value != null && value instanceof HashMap) { value = constructRefs(bridge, (Map<String, Object>) value); } else if (value != null && value instanceof ArrayList) { value = constructRefs(bridge, (List<Object>) value); } theMap.put(entry.getKey(), value); } return theMap; }  @SuppressWarnings("unchecked") static Object constructRefs(Bridge bridge, Map<String, Object> theMap); static boolean isRemoteObject(Class<?> klass); static Class<?> autobox(Class<?> klass); static Object defaultValueForPrimitive(Class<?> primitive); static final String DEFAULT_REDIRECTOR; static final BridgeEventHandler DEFAULT_EVENT_HANDLER; static final boolean DEFAULT_RECONNECT; static final String DEFAULT_SECURE_REDIRECTOR; static int logLevel; }
@Test public void testConstructRefs() { Map<String, Object> map = new HashMap<String, Object>(); map.put("a", 1.0); map.put("b", refObj); Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put("a", 1.0); resultMap.put("b", reference); assertEquals(resultMap, Utils.constructRefs(bridge, map)); List<Object> list = Arrays.asList(new Object[] { "a", "b", refObj }); List<Object> resultList = Arrays.asList(new Object[] { "a", "b", reference }); assertEquals(resultList, Utils.constructRefs(bridge, list)); List<Object> nullList = Arrays .asList(new Object[] { "a", "b", null, 2 }); List<Object> resultNullList = Arrays.asList(new Object[] { "a", "b", null, 2 }); assertEquals(resultNullList, nullList); Map<String, Object> nestMap = new HashMap<String, Object>(); nestMap.put("a", 1.0); nestMap.put("b", list); Map<String, Object> resultNestMap = new HashMap<String, Object>(); resultNestMap.put("a", 1.0); resultNestMap.put("b", resultList); assertEquals(resultNestMap, Utils.constructRefs(bridge, nestMap)); List<Object> nestList = Arrays.asList(new Object[] { "a", "b", map }); List<Object> resultNestList = Arrays.asList(new Object[] { "a", "b", resultMap }); assertEquals(resultNestList, Utils.constructRefs(bridge, nestList)); }