You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When serializing a datetime.timedelta()as part of a JSON-object, it is serialized as the total number of seconds. Support for this was introduced in #584. When using a serializers.DurationField, it is serialized as a HH:MM:DD-like string, as introduced in #2989.
This can be quite troublesome on the client, since different API:s will have different behaviour depending on their implementation. In my specific use-case we transform the data from the API into moment.js duration objects, and depending on API implementation this currently has to be done in different ways.
I realize this would be a breaking change, but I think it is worth to discuss.
The text was updated successfully, but these errors were encountered:
We could change the default implementation of JSONEncoder to handle timedelta differently, but I'm not particularly convinced at the moment. It'd be a little more consistent, but I don't think there's any absolute requirement that the default representation for DurationField should also happen to be the same as the default represention of datetime.timedelta (yes, it'd absolutely be nicer, but I wouldn't consider it a bug - these are two different cases, which happen to have the same internal type)
When serializing a
datetime.timedelta()
as part of a JSON-object, it is serialized as the total number of seconds. Support for this was introduced in #584. When using aserializers.DurationField
, it is serialized as aHH:MM:DD
-like string, as introduced in #2989.This can be quite troublesome on the client, since different API:s will have different behaviour depending on their implementation. In my specific use-case we transform the data from the API into moment.js duration objects, and depending on API implementation this currently has to be done in different ways.
I realize this would be a breaking change, but I think it is worth to discuss.
The text was updated successfully, but these errors were encountered: