diff options
| author | Lukas Hetzenecker <lukas@splots.co> | 2015-06-23 22:56:22 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-07-10 09:02:14 +0200 |
| commit | ebcfedb0e541a4840c375375ab41fc513f322b7d (patch) | |
| tree | 2a9ffdf93f54a2e624d794d7c6dbf870b8a38003 /django | |
| parent | 0db2cdb1fa9e08658d78ff58ea9bd698ea12d3fa (diff) | |
[1.8.x] Fixed #25019 -- Added UUID support in DjangoJSONEncoder
Backport of 6355a6d4f5 and 2e05ef4e18 from master.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/serializers/json.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index f67295edf9..764640465d 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, unicode_literals import datetime import decimal import json +import uuid import sys from django.core.serializers.base import DeserializationError @@ -86,7 +87,7 @@ def Deserializer(stream_or_string, **options): class DjangoJSONEncoder(json.JSONEncoder): """ - JSONEncoder subclass that knows how to encode date/time and decimal types. + JSONEncoder subclass that knows how to encode date/time, decimal types and UUIDs. """ def default(self, o): # See "Date Time String Format" in the ECMA-262 specification. @@ -108,6 +109,8 @@ class DjangoJSONEncoder(json.JSONEncoder): return r elif isinstance(o, decimal.Decimal): return str(o) + elif isinstance(o, uuid.UUID): + return str(o) else: return super(DjangoJSONEncoder, self).default(o) |
