Skip to content

Commit

Permalink
Merge pull request #18 from prakanth97/array_fix
Browse files Browse the repository at this point in the history
Fix bug in open array conversion
  • Loading branch information
prakanth97 committed May 2, 2024
2 parents 1f53bb0 + 444e7c4 commit 5ff04c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ballerina/tests/from_json_with_disable_projection_option.bal
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,10 @@ isolated function testDisableDataProjectionInRecordTypeWithParseAsType() {
test:assertTrue(val4 is error);
test:assertEquals((<error>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]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 5ff04c0

Please sign in to comment.