diff --git a/jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/spec/ShiftrCompositeSpec.java b/jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/spec/ShiftrCompositeSpec.java index 58036988..efbb73ca 100644 --- a/jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/spec/ShiftrCompositeSpec.java +++ b/jolt-core/src/main/java/com/bazaarvoice/jolt/shiftr/spec/ShiftrCompositeSpec.java @@ -201,10 +201,12 @@ private enum ExecutionStrategy { void processMap( ShiftrCompositeSpec spec, Map inputMap, WalkedPath walkedPath, Map output ) { for( String key : spec.literalChildren.keySet() ) { - Object subInput = inputMap.get( key ); - if ( subInput != null ) { - // we know the .get(key) will not return null + // only recurse down if the literalChild is a key in the input map + if ( inputMap.containsKey( key ) ) { + + // At this point subInput could be null, and that is ok + Object subInput = inputMap.get( key ); spec.literalChildren.get( key ).apply( key, subInput, walkedPath, output ); } } diff --git a/jolt-core/src/test/java/com/bazaarvoice/jolt/ShiftrTest.java b/jolt-core/src/test/java/com/bazaarvoice/jolt/ShiftrTest.java index beec218f..448cc650 100644 --- a/jolt-core/src/test/java/com/bazaarvoice/jolt/ShiftrTest.java +++ b/jolt-core/src/test/java/com/bazaarvoice/jolt/ShiftrTest.java @@ -50,6 +50,7 @@ public Object[][] getTestCaseUnits() { {"mergeParallelArrays3_and-filter"}, {"multiPlacement"}, {"objectToArray"}, + {"passNullThru"}, {"passThru"}, {"prefixDataToArray"}, {"prefixedData"}, diff --git a/jolt-core/src/test/resources/json/shiftr/passNullThru.json b/jolt-core/src/test/resources/json/shiftr/passNullThru.json new file mode 100644 index 00000000..7e2b6a31 --- /dev/null +++ b/jolt-core/src/test/resources/json/shiftr/passNullThru.json @@ -0,0 +1,26 @@ +{ + "input": { + "key": null, + "bunch-O-keys" : { + "a" : null, + "b" : null, + "c" : null + } + }, + + "spec": { + "key": "value", + "bunch-O-keys" : { + "*" : "values.&" + } + }, + + "expected": { + "value" : null, + "values" : { + "a" : null, + "b" : null, + "c" : null + } + } +}