Opened 17 years ago
Closed 17 years ago
#5553 closed (fixed)
JSON serializer imporperly serializes: datetime.datetime, datetime.time, float
Reported by: | Maciej Wiśniowski | Owned by: | nobody |
---|---|---|---|
Component: | Core (Serialization) | Version: | dev |
Severity: | Keywords: | json | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This bug was introduced after commiting patch for this ticket: http://code.djangoproject.com/ticket/4714
Original patch I've written was changed by commiter and this introduced some issues.
Problem is that now serializers/python.py uses smart_unicode(... , strings_only=True).
Unfortunatelly smart_unicode only recogizes None, int and long as not strings.
Because of this, datetime objects (as well as floats) are converted to strings.
This causes that serializers/json.py -> DjangoJSONEncoder is useless.
My, original implementation from #4714, uses function 'str_to_unicode' that converts only
instances of basestring to unicode - so it works properly.
I'm not sure why it was changed to 'smart_unicode', but if 'smart_unicode' should be used then
'force_unicodes detection of strings has to be changed.
Problem is with datetime.datetime, datetime.time, float and possibly Decimal.
I've attached a patch with tests.
Attachments (1)
Change History (2)
by , 17 years ago
comment:1 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [6406]) Fixed #5553 -- Fixed a serialization problem with datetime and time objects. Thanks to pigletto for the patch.