Skip to content

Commit

Permalink
Fix FasterXML#3882 (JsonNode.withArray() fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 16, 2023
1 parent d47d1b6 commit c7b6c64
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.14.4 (not yet released)

#3882: Error in creating nested `ArrayNode`s with `JsonNode.withArray()`
(reported by @SaiKrishna369)

2.14.3 (05-May-2023)

#3784: `PrimitiveArrayDeserializers$ByteDeser.deserialize` ignores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ protected ArrayNode _withArrayAddTailElement(JsonPointer tail, boolean preferInd
_withXxxSetArrayElement(index, next);
return next._withArrayAddTailElement(tail, preferIndex);
}
ArrayNode next = this.arrayNode();
ObjectNode next = this.objectNode();
_withXxxSetArrayElement(index, next);
return next._withArrayAddTailElement(tail, preferIndex);
return next._withArrayAddTailProperty(tail, preferIndex);
}

protected void _withXxxSetArrayElement(int index, JsonNode value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.JsonNode.OverwriteMode;

// for [databuind#1980] implementation
// for [databind#1980] implementation
public class WithPathTest extends BaseMapTest
{
private final ObjectMapper MAPPER = sharedMapper();
Expand Down Expand Up @@ -296,4 +296,23 @@ private void _verifyArrayReplaceFail(JsonNode doc, JsonPointer ptr, OverwriteMod
verifyException(e, "(mode `OverwriteMode."+mode.name()+"`)");
}
}

// [databind#3882]
public void testWithArray3882() throws Exception
{
ObjectNode root = MAPPER.createObjectNode();
ArrayNode aN = root.withArray("/key/0/a",
JsonNode.OverwriteMode.ALL, true);
aN.add(123);
assertEquals(a2q("{'key':[{'a':[123]}]}"),
root.toString());

// And then the original case
root = MAPPER.createObjectNode();
aN = root.withArray(JsonPointer.compile("/key1/array1/0/element1"),
JsonNode.OverwriteMode.ALL, true);
aN.add("v1");
assertEquals(a2q("{'key1':{'array1':[{'element1':['v1']}]}}"),
root.toString());
}
}

0 comments on commit c7b6c64

Please sign in to comment.