-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
JSONRender fails to serialize timedelta objects #392
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
Comments
See the encoder implementation: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/utils/encoders.py#L13 (Not documented as it's considered a private api) |
For timedelta, we can take a look at Mark Hildreth's approach: more precisely:
|
I don't think that approach is quite appropriate here since it encodes into such a specific format. NB. In the other direction there's no need for the JSON decoder to be able to determine and decode the type into a timedelta automagically, as that's a serializer concern. |
I think strings would be fine, because the serializer *knows *what we're James Cleveland On 9 November 2012 15:55, Tom Christie [email protected] wrote:
|
There's also the option of doing str(mytimedelta) which works, and to James Cleveland On 9 November 2012 15:57, James Cleveland [email protected] wrote:
|
So yeah, seconds is probably best, because I just realised that str(delta) James Cleveland On 9 November 2012 15:58, James Cleveland [email protected] wrote:
|
Into core is good. |
Yo. Made something for ya. ⚡ 😏 ⚡ |
#584 :O |
yeah! :D |
It's also not immediately clear as to how to override the behaviour.
The text was updated successfully, but these errors were encountered: