diff --git a/jolt-core/src/main/java/com/bazaarvoice/jolt/utils/JoltUtils.java b/jolt-core/src/main/java/com/bazaarvoice/jolt/utils/JoltUtils.java index 09483224..65532b55 100644 --- a/jolt-core/src/main/java/com/bazaarvoice/jolt/utils/JoltUtils.java +++ b/jolt-core/src/main/java/com/bazaarvoice/jolt/utils/JoltUtils.java @@ -22,9 +22,8 @@ import java.util.List; import java.util.Map; - /** - * Handy utilities that do NOT depend on JsonUtil lives here! + * Handy utilities that do NOT depend on JsonUtil / Jackson live here */ public class JoltUtils { @@ -44,13 +43,14 @@ public static void removeRecursive( Object json, String keyToRemove ) { Map jsonMap = cast(json); // If this level of the tree has the key we are looking for, remove it + // Do the lookup instead of just the remove to avoid un-necessarily + // dying on ImmutableMaps. if ( jsonMap.containsKey( keyToRemove ) ) { jsonMap.remove( keyToRemove ); } // regardless, recurse down the tree - for ( String subKey : jsonMap.keySet() ) { - Object value = jsonMap.get( subKey ); + for ( Object value : jsonMap.values() ) { removeRecursive( value, keyToRemove ); } } diff --git a/json-utils/src/main/java/com/bazaarvoice/jolt/JsonUtils.java b/json-utils/src/main/java/com/bazaarvoice/jolt/JsonUtils.java index 752cd831..dff91f46 100644 --- a/json-utils/src/main/java/com/bazaarvoice/jolt/JsonUtils.java +++ b/json-utils/src/main/java/com/bazaarvoice/jolt/JsonUtils.java @@ -63,13 +63,14 @@ public static void removeRecursive( Object json, String keyToRemove ) { Map jsonMap = (Map) json; // If this level of the tree has the key we are looking for, remove it + // Do the lookup instead of just the remove to avoid un-necessarily + // dying on ImmutableMaps. if ( jsonMap.containsKey( keyToRemove ) ) { jsonMap.remove( keyToRemove ); } // regardless, recurse down the tree - for ( String subKey : jsonMap.keySet() ) { - Object value = jsonMap.get( subKey ); + for ( Object value : jsonMap.values() ) { removeRecursive( value, keyToRemove ); } }