mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
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.
This commit is contained in:
parent
ea462b7b9b
commit
d489c5c881
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user