@SuppressWarnings("unchecked") @Test public void testStripList() { Map<String, Object> body = new HashMap<String, Object>(); List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>(); Map<String, Object> em1 = new HashMap<String, Object>(); em1.put("ek1", "ev1"); em1.put("ek2", "ev2"); Map<String, Object> em2 = new HashMap<String, Object>(); em2.put("ek1", "ev1"); em2.put("ek2", "ev2"); mapList.add(em1); mapList.add(em2); body.put("k1", mapList); EntityManipulator.removeFields(body, "k1.ek1"); assertTrue(body.get("k1") instanceof List); List<Map<String, Object>> mapListRemoved = (List<Map<String, Object>>) body.get("k1"); assertEquals(2, mapListRemoved.size()); assertEquals("ev2", mapListRemoved.get(0).get("ek2")); assertEquals(null, mapListRemoved.get(0).get("ek1")); assertEquals("ev2", mapListRemoved.get(1).get("ek2")); assertEquals(null, mapListRemoved.get(1).get("ek1")); body = new HashMap<String, Object>(); List<String> values = Arrays.asList("ev1", "ev2"); body.put("k1", values); body.put("k2", "v2"); EntityManipulator.removeFields(body, "k1"); assertEquals("v2", body.get("k2")); assertFalse(body.containsKey("k1")); body = new HashMap<String, Object>(); List<Object> el1 = new ArrayList<Object>(); List<Object> el2 = new ArrayList<Object>(); em2 = new HashMap<String, Object>(); em2.put("eek1", "eev1"); em2.put("eek2", "eev2"); el2.add(em2); em1 = new HashMap<String, Object>(); em1.put("ek1", el2); el1.add(em1); body.put("k1", el1); EntityManipulator.removeFields(body, "k1.ek1.eek1"); List<Object> k1List = (List<Object>) body.get("k1"); Map<String, Object> ek1Map = (Map<String, Object>) k1List.get(0); List<Object> ek1List = (List<Object>) ek1Map.get("ek1"); Map<String, Object> removedMap = (Map<String, Object>) ek1List.get(0); assertTrue(removedMap.containsKey("eek2")); assertEquals("eev2", removedMap.get("eek2")); assertEquals(null, removedMap.get("eek1")); }
public static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList) { if (toRemoveList == null || toRemoveList.isEmpty()) { return; } if (toRemoveFrom == null) { return; } for (final String toStrip : toRemoveList) { removeField(toRemoveFrom, toStrip); } }
EntityManipulator { public static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList) { if (toRemoveList == null || toRemoveList.isEmpty()) { return; } if (toRemoveFrom == null) { return; } for (final String toStrip : toRemoveList) { removeField(toRemoveFrom, toStrip); } } }
EntityManipulator { public static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList) { if (toRemoveList == null || toRemoveList.isEmpty()) { return; } if (toRemoveFrom == null) { return; } for (final String toStrip : toRemoveList) { removeField(toRemoveFrom, toStrip); } } private  EntityManipulator(); }
EntityManipulator { public static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList) { if (toRemoveList == null || toRemoveList.isEmpty()) { return; } if (toRemoveFrom == null) { return; } for (final String toStrip : toRemoveList) { removeField(toRemoveFrom, toStrip); } } private  EntityManipulator(); static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList); static void removeFields(final Map<String, Object> toRemoveFrom, final String toRemove); }
EntityManipulator { public static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList) { if (toRemoveList == null || toRemoveList.isEmpty()) { return; } if (toRemoveFrom == null) { return; } for (final String toStrip : toRemoveList) { removeField(toRemoveFrom, toStrip); } } private  EntityManipulator(); static void removeFields(final Map<String, Object> toRemoveFrom, final List<String> toRemoveList); static void removeFields(final Map<String, Object> toRemoveFrom, final String toRemove);  }