Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anydata support for setPayload methods #2135

Merged
merged 14 commits into from
Sep 10, 2024
Merged

Add anydata support for setPayload methods #2135

merged 14 commits into from
Sep 10, 2024

Conversation

TharmiganK
Copy link
Contributor

@TharmiganK TharmiganK commented Sep 3, 2024

Purpose

$Subject

Fixes: ballerina-platform/ballerina-library#6954

The setPayload with anydata uses the setJsonPayload with the toJson value of the anydata.

Example

// Open record
type AnydataRecord record {
    string a;
    int b;
};

AnydataRecord testValue = {a: "ballerina", b: 1};

// Request Object
http:Request req = new;
req.setPayload(testValue);

// Response Object
http:Response res = new;
res.setPayload(testValue);

Checklist

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.23%. Comparing base (d0759e0) to head (4de1320).
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2135   +/-   ##
=========================================
  Coverage     80.22%   80.23%           
  Complexity      669      669           
=========================================
  Files           408      408           
  Lines         22926    22926           
  Branches       5271     5271           
=========================================
+ Hits          18393    18395    +2     
+ Misses         3396     3395    -1     
+ Partials       1137     1136    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TharmiganK TharmiganK marked this pull request as ready for review September 3, 2024 08:14
daneshk
daneshk previously approved these changes Sep 4, 2024
Copy link
Member

@daneshk daneshk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

SasinduDilshara
SasinduDilshara previously approved these changes Sep 5, 2024
ballerina/http_request.bal Outdated Show resolved Hide resolved
ballerina/http_response.bal Show resolved Hide resolved
@@ -512,13 +512,15 @@ public class Request {

# Sets the request payload. This method overrides any existing content-type by passing the content-type
# as an optional parameter. If the content type parameter is not provided then the default value derived
# from the payload will be used as content-type only when there are no existing content-type header.
# from the payload will be used as content-type only when there are no existing content-type header. If
# the payload is non-json typed value then the value is converted to json using the `toJson` method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely an accurate description for xml, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated via #2135

#
# + payload - Payload can be of type `string`, `xml`, `json`, `byte[]`, `stream<byte[], io:Error?>`
# + payload - Payload can be of type `anydata`, `stream<byte[], io:Error?>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we have to explicitly mention xml, json, etc. as examples? Just thinking of someone getting started with Ballerina.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't suggest users to use request/response objects with setPayload methods unless it is an advanced scenario like multipart. May be we can include a more detailed description in the spec

Copy link

sonarcloud bot commented Sep 10, 2024

@TharmiganK TharmiganK merged commit 23b5add into master Sep 10, 2024
8 checks passed
@TharmiganK TharmiganK deleted the fix-set-payload branch September 10, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add anydata support in the setPayload methods
5 participants