aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils
diff options
context:
space:
mode:
authorTom Christie2013-12-13 16:32:34 +0000
committerTom Christie2013-12-13 16:32:34 +0000
commit9c41c007afc71c899306bcb02e40bdfc36b09146 (patch)
treeca0da04aed0c1b96ddf14a801dc54b5a72a72461 /rest_framework/utils
parented931b90ae9e72f963673e6e188b1802a5a65360 (diff)
parentca244ad614e2f6fb4fef1dc9987be996d2624303 (diff)
downloaddjango-rest-framework-9c41c007afc71c899306bcb02e40bdfc36b09146.tar.bz2
Merge branch 'master' into 2.4.0
Conflicts: .travis.yml docs/api-guide/routers.md docs/topics/release-notes.md rest_framework/compat.py
Diffstat (limited to 'rest_framework/utils')
-rw-r--r--rest_framework/utils/encoders.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index 13a85550..229b0b28 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -45,6 +45,11 @@ class JSONEncoder(json.JSONEncoder):
return str(o)
elif hasattr(o, 'tolist'):
return o.tolist()
+ elif hasattr(o, '__getitem__'):
+ try:
+ return dict(o)
+ except:
+ pass
elif hasattr(o, '__iter__'):
return [i for i in o]
return super(JSONEncoder, self).default(o)
@@ -90,6 +95,9 @@ else:
node.flow_style = best_style
return node
+ SafeDumper.add_representer(decimal.Decimal,
+ SafeDumper.represent_decimal)
+
SafeDumper.add_representer(SortedDict,
yaml.representer.SafeRepresenter.represent_dict)
SafeDumper.add_representer(DictWithMetadata,