diff options
| author | Omer Katz | 2014-10-02 16:44:20 +0300 |
|---|---|---|
| committer | Omer Katz | 2014-10-02 16:44:20 +0300 |
| commit | 79e91dff92443ab1f301638ac280bd3231a2ca15 (patch) | |
| tree | 26ce2feed923154d9de1b405139ae4376e4de793 | |
| parent | ffc6aa3abcb0f823b43b63db1666913565e6f934 (diff) | |
| download | django-rest-framework-79e91dff92443ab1f301638ac280bd3231a2ca15.tar.bz2 | |
The encoder now returns tuples instead of lists.
Tuples take a little less memory which is significant when serializing a lot of objects.
| -rw-r--r-- | rest_framework/utils/encoders.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index 7c4179a1..486186c9 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -45,7 +45,7 @@ class JSONEncoder(json.JSONEncoder): # Serializers will coerce decimals to strings by default. return float(obj) elif isinstance(obj, QuerySet): - return list(obj) + return tuple(obj) elif hasattr(obj, 'tolist'): # Numpy arrays and array scalars. return obj.tolist() @@ -55,7 +55,7 @@ class JSONEncoder(json.JSONEncoder): except: pass elif hasattr(obj, '__iter__'): - return [item for item in obj] + return tuple(item for item in obj) return super(JSONEncoder, self).default(obj) |
