vadymmarkov / Malibu

:surfer: Malibu is a networking library built on promises

Home Page:https://vadymmarkov.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSONSerialization cannot parse Date objects

guilhermearaujo opened this issue · comments

When I try to perform a requests with a JSON body, and passing a parameter dictionary such as

params = ["date": Date()]

the serialization performed here will fail.

From a user point-of-view, I could (and probably will, for a while), pre-convert Date objects to String, but maybe it would be interesting if Malibu could handle this automatically. Perhaps with a configuration method that accepts a format for the conversion.

Hi @guilhermearaujo! It could be a nice feature, but I don't think it's a good idea to let Malibu handle JSON transformations out-of-the-box. If we add date conversion then we'll get more requests like this for other types. As a developer you have more context and know better how to format your parameters before sending a request.

I agree with @vadymmarkov on this one, I think it can be a slippery road ahead if try support all the different combination from here to the sun. I think this can easily be solve inside the context of the project with a small nifty extension on Date. With that said, I do understand the desire for the framework to just handle this out-of-the-box. Man, it would be so create if everything was a utopia and we didn't have to handle timezones... don't get me started on timezones... I'm just gonna stop myself here.

Anyways, I'll just go head and close this one now. @guilhermearaujo thanks for using Malibu and don't be shy to make a PR if you see a need to improve upon the current implementation.

Cheers!