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

move json encoding to json operation #1061

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ex_aws/operation/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defimpl ExAws.Operation, for: ExAws.Operation.JSON do
ExAws.Request.request(
operation.http_method,
url,
operation.data,
config[:json_codec].encode!(operation.data),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here [] would be encoded as [] and not {}

headers,
config,
operation.service
Expand Down
9 changes: 1 addition & 8 deletions lib/ex_aws/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ defmodule ExAws.Request do
@type error_t :: {:error, {:http_error, http_status, binary}}
@type response_t :: success_t | error_t

def request(http_method, url, data, headers, config, service) do
body =
case data do
[] -> "{}"
Copy link
Contributor Author

@ruslandoga ruslandoga Jun 4, 2024

Choose a reason for hiding this comment

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

When is [] possible? Does it represent nil? Otherwise it might cause problems since an empty list and an empty object are not equivalent in JSON.

d when is_binary(d) -> d
_ -> config[:json_codec].encode!(data)
end

def request(http_method, url, body, headers, config, service) do
request_and_retry(http_method, url, service, config, headers, body, {:attempt, 1})
end

Expand Down
Loading