Opened 12 years ago

Closed 12 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: master
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


This bug was introduced after commiting patch for this ticket:
Original patch I've written was changed by commiter and this introduced some issues.

Problem is that now serializers/ 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/ -> 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)

json.diff (2.9 KB) - added by Maciej Wiśniowski 12 years ago.

Download all attachments as: .zip

Change History (2)

Changed 12 years ago by Maciej Wiśniowski

Attachment: json.diff added

comment:1 Changed 12 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [6406]) Fixed #5553 -- Fixed a serialization problem with datetime and time objects. Thanks to pigletto for the patch.

Note: See TracTickets for help on using tickets.
Back to Top