Skip to content

Commit

Permalink
Fix reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinAkash01 committed Nov 26, 2024
1 parent 06f7c70 commit 3d3a1c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
24 changes: 10 additions & 14 deletions ballerina/http_client_payload_builder.bal
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,23 @@ isolated function jsonPayloadBuilder(Response response, TargetType targetType, b
isolated function nonNilablejsonPayloadBuilder(Response response, typedesc<anydata> 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<anydata> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 3d3a1c1

Please sign in to comment.