Skip to content

Commit

Permalink
Fix jsonNode#addAll (#2443)
Browse files Browse the repository at this point in the history
Fix #2442: ArrayNode.addAll() needs to handle `null` entries
  • Loading branch information
heshamMassoud authored and cowtowncoder committed Sep 6, 2019
1 parent cb69a70 commit 11dfe14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public ArrayNode addAll(ArrayNode other)
*/
public ArrayNode addAll(Collection<? extends JsonNode> nodes)
{
_children.addAll(nodes);
for (JsonNode node : nodes) {
add(node);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
import static java.util.Arrays.asList;

/**
* Additional tests for {@link ArrayNode} container class.
Expand Down Expand Up @@ -186,6 +187,23 @@ public void testNullAdds()
}
}

public void testAddAllWithNullInCollection()
{
// preparation
final ArrayNode array = JsonNodeFactory.instance.arrayNode();

// test
array.addAll(asList(null, JsonNodeFactory.instance.objectNode()));

// assertions
assertEquals(2, array.size());

for (JsonNode node : array) {
assertFalse(node.isNull());
}
assertEquals(NullNode.getInstance(), array.get(0));
}

public void testNullInserts()
{
JsonNodeFactory f = objectMapper().getNodeFactory();
Expand Down

0 comments on commit 11dfe14

Please sign in to comment.