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 Moya.Response extension for Decodable types in Swift 4 #1118

Closed
SD10 opened this issue Jun 12, 2017 · 20 comments
Closed

Add Moya.Response extension for Decodable types in Swift 4 #1118

SD10 opened this issue Jun 12, 2017 · 20 comments
Assignees
Milestone

Comments

@SD10
Copy link
Member

SD10 commented Jun 12, 2017

It seems like handling response JSON is a highly debated topic due to there being so many JSON serialization libraries and no determined best practice.

However, with the addition of the Codable protocol to the Swift 4 Standard Library, I think this will become a widely used approach. I'm wondering if the Moya community would be willing to add some basic extensions to Moya.Response to map Decodable types.

Since Codable is part of the Standard Library I think it's a safe addition to Moya's core.

A rough API would be:

    func mapObject<D: Decodable>(with decoder: JSONDecoder) throws -> D {}
    func mapObject<D: Decodable>(atKeyPath keyPath: String, with decoder: JSONDecoder) throws -> D {}

Moya already supports mapping to JSON, Images, and Strings

Regardless, these are not difficult extensions to write on our own or provide in a community extension.

@BasThomas
Copy link
Contributor

Hmm, this is an interesting one. Not sure what to think of it yet.

@sunshinejr
Copy link
Member

Thanks for the issue, @SD10 - this is a really good idea. Having standardized encoding/decoding by Swift standard library, I think it is natural for us to implement a basic map method that would cover this behavior. However, for now we don't have any Swift 4.0 branch and we are in the middle of Moya 9.0 release, so we might want to wait with that implementation.

@SD10
Copy link
Member Author

SD10 commented Jun 12, 2017

@sunshinejr thank you for the feedback. I would be willing to provide the implementation for this feature when Moya is ready to start the Swift 4 migration. Including writing the Rx/Reactive extensions, documentation, and testing. If there's anything else I can do the contribute in the meantime, please feel free to let me know.

@AndrewSB
Copy link
Member

Thanks for taking the initiative @SD10! That sounds great, we'll update this issue once we cut a 9.0 release 😄

@Jeehut
Copy link
Contributor

Jeehut commented Jun 27, 2017

Please note that there is now Alamofire/Alamofire#2180 around which tracks support for the Decodable type right within Alamofire. As it is our main dependency, I think their approach to integrate this feature should be considered before finally deciding on how to implement this.

Please also note that the contributors have already confirmed that they have plans to support both Encodable and Decodable types in release version 5 in Alamofire/Alamofire#2177.

@sunshinejr sunshinejr mentioned this issue Sep 2, 2017
11 tasks
@SD10
Copy link
Member Author

SD10 commented Sep 24, 2017

@devxoul You may be interested in working on this one? I just saw RxCodable.

I have a branch that's part way through on my local copy but I thought I'd get your thoughts. Not trying to dictate contributions, just thought you may be interested 😃

@devxoul
Copy link
Member

devxoul commented Sep 25, 2017

@SD10 It looks interesting. I think I can do it :)

@sunshinejr
Copy link
Member

sunshinejr commented Sep 27, 2017

Hey @devxoul, just making sure - do you think you will want to implement this one? If not we might want to add labels to seek for help 😉

@devxoul
Copy link
Member

devxoul commented Sep 28, 2017

@sunshinejr, oh yeah I'm currently working on it. I'll make a pull request in this week :)

@sunshinejr
Copy link
Member

That's great! I assigned you to this task then 😉

@devxoul
Copy link
Member

devxoul commented Oct 1, 2017

#1335 🎉

@SD10
Copy link
Member Author

SD10 commented Oct 1, 2017

Closing this in favor of #1335. Let's move the discussion there 🎉

@SD10 SD10 closed this as completed Oct 1, 2017
@BasThomas
Copy link
Contributor

Why do we close these issues if they get auto-closed after the PR is merged? Now, if for some reason the PR isn't merged, there's a big chance this issue gets overlooked and stays closed.

@SD10
Copy link
Member Author

SD10 commented Oct 1, 2017

Good point @BasThomas. I always thought it was to encourage discussion on the PR and not have it split across two places. Feel free to reopen this and maybe we can default to the policy you described

Sent with GitHawk

@BasThomas
Copy link
Contributor

I can't remember this happening somewhere actually, and I feel like the auto-closing works best. But if I am in a minority here, I'd not want to change the way this is handled now. @Moya/contributors, what do you think?

@devxoul
Copy link
Member

devxoul commented Oct 2, 2017

I think we should keep this issue open because...

  1. there could be another pull request in different idea.
  2. this issue is not yet completely finished.

Also this is will be automatically closed if #1335 is merged.

@BasThomas
Copy link
Contributor

We can close this now :)

@devxoul
Copy link
Member

devxoul commented Oct 12, 2017

Hmm I have no idea why GitHub didn't close this issue automatically when #1335 is merged 🤔

@BasThomas
Copy link
Contributor

Think it was confused because we closed an reopened manually 😛

@devxoul
Copy link
Member

devxoul commented Oct 12, 2017

Ah, that makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants