From 3d3a1c167c32b264cac0a3771f5c8cc2ddc19a30 Mon Sep 17 00:00:00 2001 From: SachinAkash01 Date: Tue, 26 Nov 2024 13:53:48 +0530 Subject: [PATCH] Fix reviewed changes --- ballerina/http_client_payload_builder.bal | 24 ++++++++----------- .../converter/JsonToRecordConverter.java | 1 - 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ballerina/http_client_payload_builder.bal b/ballerina/http_client_payload_builder.bal index f5ca177b8..ed6a76606 100644 --- a/ballerina/http_client_payload_builder.bal +++ b/ballerina/http_client_payload_builder.bal @@ -162,27 +162,23 @@ isolated function jsonPayloadBuilder(Response response, TargetType targetType, b isolated function nonNilablejsonPayloadBuilder(Response response, typedesc targetType, boolean requireLaxDataBinding) returns anydata|ClientError { json payload = check response.getJsonPayload(); - var result = jsondata:parseAsType( - payload, - requireLaxDataBinding - ? {allowDataProjection: {nilAsOptionalField: true, absentAsNilableType: true}, enableConstraintValidation: false} - : {enableConstraintValidation: false, allowDataProjection: false}, - targetType - ); + jsondata:Options jsonParserOptions = { + enableConstraintValidation: false, + allowDataProjection: requireLaxDataBinding ? {nilAsOptionalField: true, absentAsNilableType: true} : false + }; + var result = jsondata:parseAsType(payload, jsonParserOptions, targetType); return result is error ? createPayloadBindingError(result) : result; } isolated function nilablejsonPayloadBuilder(Response response, typedesc targetType, boolean requireLaxDataBinding) returns anydata|ClientError { json|ClientError payload = response.getJsonPayload(); + jsondata:Options jsonParserOptions = { + enableConstraintValidation: false, + allowDataProjection: requireLaxDataBinding ? {nilAsOptionalField: true, absentAsNilableType: true} : false + }; if payload is json { - var result = jsondata:parseAsType( - payload, - requireLaxDataBinding - ? {allowDataProjection: {nilAsOptionalField: true, absentAsNilableType: true}, enableConstraintValidation: false} - : {enableConstraintValidation: false, allowDataProjection: false}, - targetType - ); + var result = jsondata:parseAsType(payload, jsonParserOptions, targetType); return result is error ? createPayloadBindingError(result) : result; } else { return payload is NoContentError ? () : payload; 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 fa5ef3e39..bf2e91bc2 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 @@ -39,7 +39,6 @@ import static io.ballerina.stdlib.http.api.HttpConstants.NIL_AS_OPTIONAL; import static io.ballerina.stdlib.http.api.HttpConstants.ABSENT_AS_NILABLE; - /** * The converter binds the JSON payload to a record. *