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

Fix Date decoding with custom strategy #24

Merged
merged 15 commits into from
Apr 9, 2019
Merged

Fix Date decoding with custom strategy #24

merged 15 commits into from
Apr 9, 2019

Conversation

buscarini
Copy link
Contributor

Used a try catch to be able to parse dates and optional types.

buscarini and others added 14 commits April 5, 2019 16:23
* Added coerce to be able to switch between compatible representations where only the tag changes

* Change coerce to explicitly pass the new tag. Fixed spacing issues

* Renamed coerce to coerced

* Apply suggestions from code review

Incorporated fixes for argument prefix

Co-Authored-By: buscarini <buscarini@gmail.com>
* XcodeGen

* 4.2

* Bump sim

* Update package names

* Bump Xcode
* Add tests for playgrounds.

* Update Makefile

Co-Authored-By: mbrandonw <mbw234@gmail.com>
* Time

* Money

* typo

* podspecs

* update readme

* comment about currencies

* date conversions and more tests

* positive examples in readme

* clean up

* more cleanup

* Update README.md

* wip

* Update Tagged.podspec

* clean up

* clean u

* Bump

* Update Podspecs

* run make xcodeproj

* dependency

* make xcodeproj

* Bundle XcodeGen. Ignore Package.resolved
* Add workspace

* Swift 5

* Bumps

* Workaround for Swift bug.

* Bumps

* Bump 2

* Podspecs

* Use Swift 5 Docker

* Conditionally include development dependencies

* Use PF-prefixed environment variable to scope

* Update TaggedTests.swift

* Revert "Update TaggedTests.swift"

This reverts commit b5bea0b.
@stephencelis
Copy link
Member

@buscarini Thanks for the PR! Looks like this branch doesn't merge cleanly, though. Can you reset your branch to origin/master, cherry-pick your commits back onto it, and then force-push this branch?

@buscarini
Copy link
Contributor Author

I think now it should be fixed and can be merged.

@stephencelis
Copy link
Member

Looks great, thanks!

@stephencelis stephencelis merged commit d39bcf4 into pointfreeco:master Apr 9, 2019
@@ -35,7 +35,12 @@ extension Tagged: Comparable where RawValue: Comparable {

extension Tagged: Decodable where RawValue: Decodable {
public init(from decoder: Decoder) throws {
self.init(rawValue: try .init(from: decoder))
do {
self.init(rawValue: try decoder.singleValueContainer().decode(RawValue.self))
Copy link
Contributor

@pteasima pteasima Jul 7, 2019

Choose a reason for hiding this comment

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

@buscarini Can you explain the difference between going through the container vs straight from decoder?

Im working on a related problem: with Pointfreeco's ArbitraryDecoder, if I go through the container I can customize whats being decoded (which I need e.g. for String based enums, which almost certainly fail from an arbitrary string).

But it would help if I understood the difference between the two approaches for your usecase, so that I dont introduce unexpected bugs.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Specifically, I consider going through the container to be the correct way (it gives the decoder a chance to do whatever it needs to do). So I wonder which usecase it breaks (why is the catch needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This pull request is related to #23

I don't remember all the details right now, but I think the problem is that with the container there was an issue with decoding optionals, and using the init directly skipped custom date decoding strategies, so this was the only solution that fixed both issues. You can check this by downloading the repository, commenting each strategy and trying to pass the tests. You will see that in each case one test fails.

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.

4 participants