From 444e7c476bba829ef7b0bd5c423c76e54640f0da Mon Sep 17 00:00:00 2001 From: prakanth <50439067+prakanth97@users.noreply.github.com> Date: Thu, 2 May 2024 17:38:17 +0530 Subject: [PATCH] Fix bug in open array conversion --- .../tests/from_json_with_disable_projection_option.bal | 7 +++++++ .../io/ballerina/lib/data/jsondata/json/JsonTraverse.java | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ballerina/tests/from_json_with_disable_projection_option.bal b/ballerina/tests/from_json_with_disable_projection_option.bal index 1d2d565..34b89ad 100644 --- a/ballerina/tests/from_json_with_disable_projection_option.bal +++ b/ballerina/tests/from_json_with_disable_projection_option.bal @@ -297,3 +297,10 @@ isolated function testDisableDataProjectionInRecordTypeWithParseAsType() { test:assertTrue(val4 is error); test:assertEquals((val4).message(), "undefined field 'company1'"); } + +@test:Config +isolated function testDisableProjectionForOpenArray() returns error? { + string jsonStr = string `[1, 2, 3, 4]`; + int[] val = check parseString(jsonStr, options); + test:assertEquals(val, [1, 2, 3, 4]); +} diff --git a/native/src/main/java/io/ballerina/lib/data/jsondata/json/JsonTraverse.java b/native/src/main/java/io/ballerina/lib/data/jsondata/json/JsonTraverse.java index 58bd9ba..90d74f4 100644 --- a/native/src/main/java/io/ballerina/lib/data/jsondata/json/JsonTraverse.java +++ b/native/src/main/java/io/ballerina/lib/data/jsondata/json/JsonTraverse.java @@ -229,7 +229,8 @@ private Object traverseArrayValue(BArray array, Object currentJsonNode) { ArrayType arrayType = (ArrayType) rootArray; int expectedArraySize = arrayType.getSize(); long sourceArraySize = array.getLength(); - if (!allowDataProjection && expectedArraySize < sourceArraySize) { + if (!allowDataProjection && arrayType.getState() == ArrayType.ArrayState.CLOSED + && expectedArraySize < sourceArraySize) { throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); }