From 79e91dff92443ab1f301638ac280bd3231a2ca15 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 2 Oct 2014 16:44:20 +0300 Subject: [PATCH] The encoder now returns tuples instead of lists. Tuples take a little less memory which is significant when serializing a lot of objects. --- rest_framework/utils/encoders.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index 7c4179a1f..486186c94 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)