aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils/encoders.py
diff options
context:
space:
mode:
authorTom Christie2013-12-09 08:50:31 +0000
committerTom Christie2013-12-09 08:50:31 +0000
commita6ca943faa42af30075e260a01d7e672f706d3fd (patch)
tree0e8b0229b0562906ae5541f81fc1d4ca3f024f8f /rest_framework/utils/encoders.py
parentc1be503308e755d72aae2c9695739bd33631e18b (diff)
parent6af31ed3945fd051a6e8c08851d7a656637d1f00 (diff)
downloaddjango-rest-framework-a6ca943faa42af30075e260a01d7e672f706d3fd.tar.bz2
Merge branch 'issue-1231-jsonencoder' of git://github.com/mbox/django-rest-framework into mbox-issue-1231-jsonencoder
Diffstat (limited to 'rest_framework/utils/encoders.py')
-rw-r--r--rest_framework/utils/encoders.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index 35ad206b..22b1ab3d 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -44,6 +44,12 @@ class JSONEncoder(json.JSONEncoder):
return str(o)
elif hasattr(o, 'tolist'):
return o.tolist()
+ elif hasattr(o, '__getitem__'):
+ try:
+ return dict(o)
+ except KeyError:
+ # Couldn't convert to a dict, fall through
+ pass
elif hasattr(o, '__iter__'):
return [i for i in o]
return super(JSONEncoder, self).default(o)