From 7db9b51fa8cfaaf80999d1c70cd49d3f35d14692 Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Fri, 17 Jan 2025 13:35:30 +0530 Subject: [PATCH 1/5] Add relaxed data binding features to the module spec --- docs/spec/spec.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 0fe9d5f32f..0640b5362f 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -353,6 +353,20 @@ The service implemented via the service contract type has the following restrict - The base path is not allowed in the service declaration, and it is inferred from the service contract type. - The service declaration cannot have additional resource methods which are not defined in the service contract type. +### 2.2.7. Relaxed data binding + +Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields +to reduce type conversion errors and better align with inconsistent API responses. +- For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing +runtime failures. +- For required fields that are absent in the response are treated as null values instead of causing runtime failures. + +```ballerina +@http:ServiceConfig { + laxDataBinding: true +} +``` + ### 2.3. Resource A method of a service can be declared as a [resource method](https://ballerina.io/spec/lang/2021R1/#resources) @@ -1181,6 +1195,7 @@ public type ClientConfiguration record {| ClientSecureSocket? secureSocket = (); ProxyConfig? proxy = (); boolean validation = true; + laxDataBinding = false; |}; public type ClientHttp1Settings record {| @@ -1349,6 +1364,20 @@ public function main() { } ``` +##### 2.4.1.10 Relaxed data binding client + +Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields +to reduce type conversion errors and better align with inconsistent API responses. +- For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing +runtime failures. +- For required fields that are absent in the response are treated as null values instead of causing runtime failures. + +```ballerina +final http:Client relaxedClientEP = check new ("http://localhost:9090, { + laxDataBinding = true +}); +``` + ##### 2.4.2. Client action The HTTP client contains separate remote method representing each HTTP method such as `get`, `put`, `post`, From 7fe961368c40097b1cb814fc3f4f62e7dbb73e5c Mon Sep 17 00:00:00 2001 From: Sachin Akash Date: Sun, 19 Jan 2025 23:56:14 +0530 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Krishnananthalingam Tharmigan <63336800+TharmiganK@users.noreply.github.com> --- docs/spec/spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 0640b5362f..7661e618c3 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -356,7 +356,7 @@ The service implemented via the service contract type has the following restrict ### 2.2.7. Relaxed data binding Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields -to reduce type conversion errors and better align with inconsistent API responses. +to reduce type conversion errors and better align with inconsistent API requests. - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. - For required fields that are absent in the response are treated as null values instead of causing runtime failures. From db00e84940320fd5f8b88372714dbb12e1a89101 Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Mon, 20 Jan 2025 00:03:15 +0530 Subject: [PATCH 3/5] Resolve the review suggestions --- docs/spec/spec.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 0640b5362f..f98532562c 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -355,8 +355,7 @@ The service implemented via the service contract type has the following restrict ### 2.2.7. Relaxed data binding -Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields -to reduce type conversion errors and better align with inconsistent API responses. +The following rules applies for relaxed data binding in addition to data projection. - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. - For required fields that are absent in the response are treated as null values instead of causing runtime failures. @@ -1366,16 +1365,13 @@ public function main() { ##### 2.4.1.10 Relaxed data binding client -Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields -to reduce type conversion errors and better align with inconsistent API responses. +The following rules applies for relaxed data binding in addition to data projection. - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. - For required fields that are absent in the response are treated as null values instead of causing runtime failures. ```ballerina -final http:Client relaxedClientEP = check new ("http://localhost:9090, { - laxDataBinding = true -}); +final http:Client relaxedClientEP = check new ("http://localhost:9090", laxDataBinding = true); ``` ##### 2.4.2. Client action From 85b3cd9fa68843356f16a91ec323d91c55637416 Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Mon, 20 Jan 2025 00:13:35 +0530 Subject: [PATCH 4/5] Refactor the structure --- docs/spec/spec.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 02a7e9bf8d..10719fbfb0 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -357,6 +357,9 @@ The service implemented via the service contract type has the following restrict Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields to reduce type conversion errors and better align with inconsistent API requests. + +The following rules applies for relaxed data binding in addition to data projection, + - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. - For required fields that are absent in the response are treated as null values instead of causing runtime failures. @@ -1366,7 +1369,11 @@ public function main() { ##### 2.4.1.10 Relaxed data binding client +Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields +to reduce type conversion errors and better align with inconsistent API responses. + The following rules applies for relaxed data binding in addition to data projection. + - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. - For required fields that are absent in the response are treated as null values instead of causing runtime failures. From 8818a156e767b513852b3d8e793dec9498aea08c Mon Sep 17 00:00:00 2001 From: Sachin Akash Date: Tue, 21 Jan 2025 09:14:34 +0530 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Krishnananthalingam Tharmigan <63336800+TharmiganK@users.noreply.github.com> --- docs/spec/spec.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 10719fbfb0..9afb5c2937 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -358,7 +358,7 @@ The service implemented via the service contract type has the following restrict Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields to reduce type conversion errors and better align with inconsistent API requests. -The following rules applies for relaxed data binding in addition to data projection, +The following additional rules applies to data projection used for the relaxed data binding, - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures. @@ -1372,7 +1372,7 @@ public function main() { Enables relaxed data binding for the JSON payload binding process, allowing graceful handling of null values and absent fields to reduce type conversion errors and better align with inconsistent API responses. -The following rules applies for relaxed data binding in addition to data projection. +The following additional rules applies to data projection used for the relaxed data binding, - For fields that are marked as optional but non-nullable, null values in the response are treated as absent fields instead of causing runtime failures.