-
Notifications
You must be signed in to change notification settings - Fork 62
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 Date marshalling with different formatters #73
Comments
Good question. What sort of formats are you getting? I think there are a couple ways you might be able to deal with this: let dateString: String = json.value(for: "someDate")
let date = myDateFormatter.date(from: dateString)
There are probably other ways to go about it, but that's what came to me off the top of my head. I'm sorry there's not something built in for this—dates are complicated... which is why we left them as an exercise for the user. We used to have dates built in but removed them for that reason. Definitely open to suggestions though, if you have any ideas I'd love to hear them. |
Here are my quick impressions:
|
What about something like this?: |
Oh yes, 1 was not intended to be elegant and 3 was not supposed to be performant :) I'm not as concerned by providing everything that other JSON decoders provide as I am doing the right thing for Marshal. Changing the API as Bart suggests is a much easier/better way to inject a transformer into the decoding process and is something I've thought about—there's just a balance between adding features to the framework to handle different cases and keeping the framework small, which is why we removed the original implementation of date handling. I don't think dates are the only thing that would ever potentially need some sort of transformer to pass along—so potentially adding a new protocol would be appropriate... but that's API growth. I am far from opposed to adding new API, but we need to be critical about it or Marshal will grow beyond a comfortable size. |
And there's not really a lot of documentation about this but Marshal's intent is not to solely to be a JSON decoding framework, but more general than that—which is why the |
All this said, I would love to see a proposal with a new protocol with a function like @bwhiteley suggested, and maybe then we can discuss how the API changes more concretely. |
Since we're talking about |
What about making Date conform to |
@KingOfBrian I think that could be a good solution, although perhaps not ideal semantically. I'd be ok having some additional API if it's not a huge addition and it adds clarity/value. |
I'm currently using Unbox but am seriously thinking of switching to Marshal. But it has one major problem for me. The way that
Date
gets marshalling support by conforming to a protocol means I can't have dates parsed with different formatters. This is a real problem for applications that needs to parse JSON from different APIs that represent dates differently.Any ideas of improving this?
The text was updated successfully, but these errors were encountered: