Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24916 closed Bug (wontfix)

DjangoJSONEncoder: Decimal type localization mechanism is missing

Reported by: Vladimir Chub Owned by: nobody
Component: Core (Serialization) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, DjangoJSONEncoder officially supports Decimal types. But localization of this type aren't using.
In current version of code, Decimal variable simply converts to str type, without use of force_text and formats.localize (as in "localize" Django standard template tag).

Change History (2)

comment:1 by Tim Graham, 9 years ago

Resolution: wontfix
Status: newclosed

The JSON standard for serializing decimal values does not provide for localized formatting. (See JSON.org.) This is why values are not localized. I think it would also make the date less portable across locales.

If you need localized values, then I'd suggest to create a custom encoder for your serializer of choice which outputs the decimals appropriately.

If you disagree and feel this is something Django should provide, please raise the issue on the DevelopersMailingList.

comment:2 by Vladimir Chub, 9 years ago

The JSON standard for serializing decimal values does not provide for localized formatting. (See JSON.org.) This is why values are not localized. I think it would also make the date less portable across locales.

By following this, support of Decimals in DjangoJSONEncoder makes sense only for web-applications that don't use localizations.

If you need localized values, then I'd suggest to create a custom encoder for your serializer of choice which outputs the decimals appropriately.

Ok, but DjangoJSONEncoder has only one method: "default", what making it hard to override. How about to divide it to different methods? It would be very helpful.

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