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

Support for JSONDecoder #210

Closed
aasatt opened this issue Sep 28, 2017 · 8 comments
Closed

Support for JSONDecoder #210

aasatt opened this issue Sep 28, 2017 · 8 comments

Comments

@aasatt
Copy link
Contributor

aasatt commented Sep 28, 2017

With Swift 4 we have JSONDecoder to make Data to our objects. No need to go through array or dictionary body. To use Networking with this it seems we have to turn these results back into JSON data and then pass it into the decoder.

What do you think the best way to get the raw data from the result would be?

I was thinking just a .data parameter along with .arrayBody and .dictionaryBody on the ResultType.Success

Would you be open to something like this?

@3lvis
Copy link
Owner

3lvis commented Sep 28, 2017

Hi Aaron!

Adding .data to the ResultType.Success sounds like the best solution for this. 👌 Go for it!

@aasatt
Copy link
Contributor Author

aasatt commented Sep 29, 2017

Can't decide on the best way to implement this.

Do you think it's acceptable to convert back to data on the fly when requested? Or do we need to go as far back as handleJSONRequest where the data is deserialized?

@3lvis
Copy link
Owner

3lvis commented Sep 29, 2017

Made a PR for this, need to add unit tests.

#211

@3lvis
Copy link
Owner

3lvis commented Sep 29, 2017

Hi @aasatt, could you check master and see if it is what you needed?

Best :)

@3lvis
Copy link
Owner

3lvis commented Oct 1, 2017

Added a data accessor to the response that should return the same data returned by URLSession.

let networking = Networking(baseURL: baseURL)
let expectedBody = ["user-agent": "hi mom!"]
networking.headerFields = expectedBody
networking.get("/user-agent") { result in
switch result {
case let .success(response):
XCTAssertEqual(response.data.toStringStringDictionary().debugDescription, expectedBody.debugDescription)
case .failure:
XCTFail()
}
}

@3lvis
Copy link
Owner

3lvis commented Oct 1, 2017

I hope this helps. Let me know if I can help with anything else :)

@3lvis 3lvis closed this as completed Oct 1, 2017
@aasatt
Copy link
Contributor Author

aasatt commented Oct 2, 2017

Didn't get a chance to look at it until now. Looks great! Thank you for this!

@3lvis
Copy link
Owner

3lvis commented Oct 2, 2017

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

No branches or pull requests

2 participants