aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils
diff options
context:
space:
mode:
authorDavid Pretty2013-09-13 13:36:18 +1000
committerDavid Pretty2013-09-13 13:36:18 +1000
commitd489c5c88144a25ef0d61fb8deb0b77f3a061480 (patch)
treebba6679a54d8dc13a8b1adcb6c86b4bddcb1b5aa /rest_framework/utils
parentea462b7b9b28f425c8c91d10e34532ddbb3c87fa (diff)
downloaddjango-rest-framework-d489c5c88144a25ef0d61fb8deb0b77f3a061480.tar.bz2
Let JSONEncoder handle Numpy data types.
json.JSONEncoder cannot serialize Numpy data types. Numpy arrays and array scalars have a tolist() method which casts the object to a standard python data type.
Diffstat (limited to 'rest_framework/utils')
-rw-r--r--rest_framework/utils/encoders.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py
index b26a2085..7efd5417 100644
--- a/rest_framework/utils/encoders.py
+++ b/rest_framework/utils/encoders.py
@@ -42,6 +42,8 @@ class JSONEncoder(json.JSONEncoder):
return str(o.total_seconds())
elif isinstance(o, decimal.Decimal):
return str(o)
+ elif hasattr(o, 'tolist'):
+ return o.tolist()
elif hasattr(o, '__iter__'):
return [i for i in o]
return super(JSONEncoder, self).default(o)