From f14cc89cf7f4c3381606f420db3cc4d37d77476e Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 13:49:12 +0530 Subject: [PATCH 1/5] Enable disabled tests --- ...vice_dispatching_data_binding_anydata_test.bal | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal index e46bcccc7e..354ae23da9 100755 --- a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal +++ b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal @@ -771,8 +771,7 @@ function testDataBindingXmlNegative() { } } -// TODO: enable after fixing https://github.com/ballerina-platform/ballerina-lang/issues/38715 -@test:Config {enable: false} +@test:Config {} function testDataBindingXmlArray() { xml[] j = [xml `WSO2`, xml `Ballerina`]; http:Response|error response = anydataBindingClient->post("/anydataB/checkXmlArray", j.toJson()); @@ -785,8 +784,7 @@ function testDataBindingXmlArray() { } } -// TODO: enable after fixing https://github.com/ballerina-platform/ballerina-lang/issues/38715 -@test:Config {enable: false} +@test:Config {} function testDataBindingXmlArrayByType() { xml[] j = [xml `WSO2`, xml `Ballerina`]; http:Response|error response = anydataBindingClient->post("/anydataB/checkXmlArray", j.toJson(), @@ -799,8 +797,7 @@ function testDataBindingXmlArrayByType() { } } -// TODO: enable after fixing https://github.com/ballerina-platform/ballerina-lang/issues/38715 -@test:Config {enable: false} +@test:Config {} function testDataBindingWithMapOfXml() { xml wso2 = xml `WSO2`; xml bal = xml `Ballerina`; @@ -815,8 +812,7 @@ function testDataBindingWithMapOfXml() { } } -// TODO: enable after fixing https://github.com/ballerina-platform/ballerina-lang/issues/38715 -@test:Config {enable: false} +@test:Config {} function testDataBindingWithMapOfXmlByType() returns error? { xml wso2 = xml `WSO2`; xml bal = xml `Ballerina`; @@ -832,8 +828,7 @@ function testDataBindingWithMapOfXmlByType() returns error? { } } -// TODO: enable after fixing https://github.com/ballerina-platform/ballerina-lang/issues/38715 -@test:Config {enable: false} +@test:Config {} function testDataBindingWithTableofMapOfXml() { xml wso2 = xml `WSO2`; xml bal = xml `Ballerina`; From d575e8666d000bede28ef3f532162a2fe04be367 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 13:50:53 +0530 Subject: [PATCH 2/5] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- ballerina/Dependencies.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 1c1c85f8a6..3933e5b963 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -19,7 +19,7 @@ path = "../native/build/libs/http-native-2.7.0-SNAPSHOT.jar" groupId = "io.ballerina.stdlib" artifactId = "mime-native" version = "2.7.0" -path = "./lib/mime-native-2.7.0-20230403-120400-3dbbe01.jar" +path = "./lib/mime-native-2.7.0-20230404-141500-dadad37.jar" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ea4fb011d4..db49663193 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.5.0-20230401-003700-e9cbdd41" +distribution-version = "2201.5.0-20230404-105200-b8aec90e" [[package]] org = "ballerina" From b6815a7f8b8e7bda11ff9ca48d7c0c1140ba5620 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 13:55:43 +0530 Subject: [PATCH 3/5] Use convert API instead of fromJsonWithType --- .../http/api/service/signature/AllQueryParams.java | 8 ++------ .../http/api/service/signature/ParamUtils.java | 6 +++--- .../signature/builder/JsonPayloadBuilder.java | 13 ++++--------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/AllQueryParams.java b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/AllQueryParams.java index 9b7b190fe9..2d290f2467 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/AllQueryParams.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/AllQueryParams.java @@ -27,15 +27,14 @@ import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BArray; -import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BRefValue; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.http.api.HttpConstants; import io.ballerina.stdlib.http.api.HttpUtil; import io.ballerina.stdlib.http.transport.message.HttpCarbonMessage; -import org.ballerinalang.langlib.value.FromJsonWithType; import java.util.ArrayList; import java.util.List; @@ -119,10 +118,7 @@ public void populateFeed(HttpCarbonMessage httpCarbonMessage, ParamHandler param paramFeed[index++] = paramArray; } else if (paramType.getTag() == MAP_TAG || paramType.getTag() == RECORD_TYPE_TAG) { Object json = JsonUtils.parse(queryValueArr.getBString(0).getValue()); - Object param = FromJsonWithType.convert(json, paramType); - if (param instanceof BError) { - throw (BError) param; - } + Object param = ValueUtils.convert(json, paramType); if (queryParam.isReadonly() && param instanceof BRefValue) { ((BRefValue) param).freezeDirect(); } diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/ParamUtils.java b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/ParamUtils.java index b654052029..4c1c6a5089 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/ParamUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/ParamUtils.java @@ -26,9 +26,9 @@ import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.stdlib.http.api.BallerinaConnectorException; -import org.ballerinalang.langlib.value.FromJsonWithType; import static io.ballerina.runtime.api.TypeTags.BOOLEAN_TAG; import static io.ballerina.runtime.api.TypeTags.DECIMAL_TAG; @@ -58,7 +58,7 @@ public static Object castParam(int targetParamTypeTag, String argValue) { return ValueCreator.createDecimalValue(argValue); case MAP_TAG: Object json = JsonUtils.parse(argValue); - return FromJsonWithType.convert(json, MAP_TYPE); + return ValueUtils.convert(json, MAP_TYPE); default: return StringUtils.fromString(argValue); } @@ -100,7 +100,7 @@ private static BArray getBArray(String[] valueArray, ArrayType arrayType, Type e case MAP_TAG: case RECORD_TYPE_TAG: Object record = JsonUtils.parse(element); - arrayValue.add(index++, FromJsonWithType.convert(record, elementType)); + arrayValue.add(index++, ValueUtils.convert(record, elementType)); break; default: throw new BallerinaConnectorException("Illegal state error: unexpected param type"); diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/builder/JsonPayloadBuilder.java b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/builder/JsonPayloadBuilder.java index b10fd39cf4..c66147d8c9 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/builder/JsonPayloadBuilder.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/builder/JsonPayloadBuilder.java @@ -19,14 +19,12 @@ package io.ballerina.stdlib.http.api.service.signature.builder; import io.ballerina.runtime.api.TypeTags; -import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.Type; -import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BRefValue; import io.ballerina.stdlib.http.api.service.signature.converter.JsonToRecordConverter; import io.ballerina.stdlib.mime.util.EntityBodyHandler; -import org.ballerinalang.langlib.value.FromJsonWithType; /** * The json type payload builder. @@ -47,12 +45,9 @@ public Object getValue(BObject entity, boolean readonly) { if (isSubtypeOfAllowedType(payloadType, TypeTags.RECORD_TYPE_TAG)) { return JsonToRecordConverter.convert(payloadType, entity, readonly); } - Object bjson = EntityBodyHandler.constructJsonDataSource(entity); - EntityBodyHandler.addJsonMessageDataSource(entity, bjson); - var result = FromJsonWithType.fromJsonWithType(bjson, ValueCreator.createTypedescValue(payloadType)); - if (result instanceof BError) { - throw (BError) result; - } + Object bJson = EntityBodyHandler.constructJsonDataSource(entity); + EntityBodyHandler.addJsonMessageDataSource(entity, bJson); + Object result = ValueUtils.convert(bJson, payloadType); if (readonly && result instanceof BRefValue) { ((BRefValue) result).freezeDirect(); } From ad69c88fe543e47e1ca1faae14b485a53ab90fc4 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 14:08:00 +0530 Subject: [PATCH 4/5] Use convert API instead of cloneWithType --- .../signature/converter/JsonToRecordConverter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/converter/JsonToRecordConverter.java b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/converter/JsonToRecordConverter.java index fd0e714857..457377226c 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/converter/JsonToRecordConverter.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/service/signature/converter/JsonToRecordConverter.java @@ -19,12 +19,12 @@ package io.ballerina.stdlib.http.api.service.signature.converter; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BRefValue; import io.ballerina.stdlib.http.api.BallerinaConnectorException; import io.ballerina.stdlib.mime.util.EntityBodyHandler; -import org.ballerinalang.langlib.value.CloneWithType; /** * The converter binds the JSON payload to a record. @@ -55,12 +55,12 @@ private static Object getRecordEntity(BObject entity, Type entityBodyType) { * Convert a json to the relevant record type. * * @param entityBodyType Represents entity body type - * @param bjson Represents the json value that needs to be converted + * @param bJson Represents the json value that needs to be converted * @return the relevant ballerina record or object */ - private static Object getRecord(Type entityBodyType, Object bjson) { + private static Object getRecord(Type entityBodyType, Object bJson) { try { - return CloneWithType.convert(entityBodyType, bjson); + return ValueUtils.convert(bJson, entityBodyType); } catch (NullPointerException ex) { throw new BallerinaConnectorException("cannot convert payload to record type: " + entityBodyType.getName()); From b9d73c58bf7e30c55aff4d085cba52cd1f7f600c Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Mon, 10 Apr 2023 17:09:15 +0530 Subject: [PATCH 5/5] Fix failing tests --- .../service_dispatching_data_binding_anydata_test.bal | 2 +- .../tests/service_dispatching_data_binding_test.bal | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal index 354ae23da9..342fbba8b4 100755 --- a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal +++ b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_anydata_test.bal @@ -569,7 +569,7 @@ function testDataBindingWithTableofMapOfStringByTypeNegative() returns error? { if response is http:Response { test:assertEquals(response.statusCode, 400, msg = "Found unexpected output"); common:assertTrueTextPayload(response.getTextPayload(), - "data binding failed: {ballerina/lang.value}ConversionError"); + "data binding failed: {ballerina}ConversionError"); } else { test:assertFail(msg = "Found unexpected output type: " + response.message()); } diff --git a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_test.bal b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_test.bal index 70359ba410..c314639206 100644 --- a/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_test.bal +++ b/ballerina-tests/http-dispatching-tests/tests/service_dispatching_data_binding_test.bal @@ -352,7 +352,7 @@ function testDataBindingIncompatibleXMLPayload() { if response is http:Response { test:assertEquals(response.statusCode, 400, msg = "Found unexpected output"); common:assertTrueTextPayload(response.getTextPayload(), - "data binding failed: {ballerina/lang.value}ConversionError"); + "data binding failed: {ballerina}ConversionError"); } else { test:assertFail(msg = "Found unexpected output type: " + response.message()); } @@ -390,8 +390,8 @@ function testDataBindingStructWithNoMatchingContent() { http:Response|error response = dataBindingClient->post("/dataBinding/body6", req); if response is http:Response { test:assertEquals(response.statusCode, 400, msg = "Found unexpected output"); - common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina/lang"); - common:assertTrueTextPayload(response.getTextPayload(), ".value}ConversionError, {\"message\":\"'map' "); + common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina"); + common:assertTrueTextPayload(response.getTextPayload(), "}ConversionError, {\"message\":\"'map' "); common:assertTrueTextPayload(response.getTextPayload(), "value cannot be converted to 'http_dispatching_tests:Person':"); common:assertTrueTextPayload(response.getTextPayload(), "missing required field 'age' of type 'int' in record 'http_dispatching_tests:Person'"); common:assertTrueTextPayload(response.getTextPayload(), "field 'team' cannot be added to the closed record 'http_dispatching_tests:Person'\""); @@ -407,7 +407,7 @@ function testDataBindingStructWithInvalidTypes() { http:Response|error response = dataBindingClient->post("/dataBinding/body7", req); if response is http:Response { test:assertEquals(response.statusCode, 400, msg = "Found unexpected output"); - common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina/lang.value}"); + common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina}"); common:assertTrueTextPayload(response.getTextPayload(), "'map' value cannot be converted to 'http_dispatching_tests:Stock'"); common:assertTrueTextPayload(response.getTextPayload(), "missing required field 'price' of type 'float' in record 'http_dispatching_tests:Stock'"); common:assertTrueTextPayload(response.getTextPayload(), "missing required field 'id' of type 'int' in record 'http_dispatching_tests:Stock'"); @@ -425,7 +425,7 @@ function testDataBindingWithRecordArrayNegative() { http:Response|error response = dataBindingClient->post("/dataBinding/body8", req); if response is http:Response { test:assertEquals(response.statusCode, 400, msg = "Found unexpected output"); - common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina/lang.value}" + + common:assertTrueTextPayload(response.getTextPayload(), "data binding failed: {ballerina}" + "ConversionError, {\"message\":\"'json[]' value cannot be converted to 'http_dispatching_tests:Person[]'"); } else { test:assertFail(msg = "Found unexpected output type: " + response.message());