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

added jsondecoding/encoding key support for smart unwrap requests #112

Merged
merged 1 commit into from
Dec 15, 2022
Merged
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
6 changes: 6 additions & 0 deletions Netable/Netable/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public extension Request where
decoder.userInfo = [
.smartUnwrapKey: smartUnwrapKey
]
decoder.dateDecodingStrategy = .iso8601
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the motivation for adding this line? Isn't this the default anyways?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was just for consistency, as I wanted to this request to have the same decoding structure as the original request. Line 120 & 121 in the original file are what I wanted to bring to the request, so we didn't meet weird discrepancies if including unwrap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense, i didnt realize we did that in request already!

decoder.keyDecodingStrategy = jsonKeyDecodingStrategy ?? defaultDecodingStrategy


guard arrayDecodeStrategy == .lossy else {
return try decoder.decode(SmartUnwrap<FinalResource>.self, from: data)
Expand Down Expand Up @@ -228,6 +231,9 @@ public extension Request where RawResource == SmartUnwrap<FinalResource> {
decoder.userInfo = [
.smartUnwrapKey: smartUnwrapKey
]
decoder.dateDecodingStrategy = .iso8601
decoder.keyDecodingStrategy = jsonKeyDecodingStrategy ?? defaultDecodingStrategy

let decodedResult = try decoder.decode(SmartUnwrap<FinalResource>.self, from: data)
return decodedResult
} catch {
Expand Down