Skip to content

Commit

Permalink
Add some precesses about not existing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
civitaspo committed Oct 29, 2015
1 parent b1bfbb3 commit 6ac47e9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/embulk/filter/json_key/JsonKeyFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public JsonNode doFilter(JsonNode rootNode)
// TODO: addKey is overwriting existing values.
private JsonNode addKey(JsonNode node, List<String> nestedKey, JsonNode value)
{
if (node == null) {
return null;
}

if (node.isObject()) {
return addKeyToObject(node, nestedKey, value);
}
Expand Down Expand Up @@ -131,7 +135,9 @@ else if (nestedKey.size() == 1) {
String parentKey = nestedKey.get(0);
List<String> newNestedKey = nestedKey.subList(1, nestedKey.size());
JsonNode newNode = addKey(object.get(parentKey), newNestedKey, value);
object.set(parentKey, newNode);
if (newNode != null) {
object.set(parentKey, newNode);
}
return object;
}
}
Expand All @@ -156,7 +162,9 @@ else if (nestedKey.size() == 1) {
if (NumberUtils.isNumber(parentIdx)) {
int idx = Integer.parseInt(parentIdx);
JsonNode newNode = addKey(object.get(idx), newNestedKey, value);
object.set(idx, newNode);
if (newNode != null) {
object.set(idx, newNode);
}
}
return object;
}
Expand Down

0 comments on commit 6ac47e9

Please sign in to comment.