diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index bf1ae2551f..489349e707 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -4,8 +4,10 @@ Project: jackson-databind === Releases === ------------------------------------------------------------------------ -2.15.1 (not yet released) +2.15.1 (16-May-2023) +#3882: Error in creating nested `ArrayNode`s with `JsonNode.withArray()` + (reported by @SaiKrishna369) #3894: Only avoid Records fields detection for deserialization (contributed by Sim Y-T) #3895: 2.15.0 breaking behaviour change for records and Getter Visibility diff --git a/src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java b/src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java index 0f1ac43b7e..06e2800e68 100644 --- a/src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java +++ b/src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java @@ -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) { diff --git a/src/test/java/com/fasterxml/jackson/databind/node/WithPathTest.java b/src/test/java/com/fasterxml/jackson/databind/node/WithPathTest.java index f3e86cc986..73cbf1e1e2 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/WithPathTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/WithPathTest.java @@ -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(); @@ -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()); + } }