From d8b84cac9170d26b8a7033c2c7ff7a6620ac81b6 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 22 Sep 2006 13:26:07 +0000 Subject: [PATCH] Fixed #2515 -- Allow passing of options to JSON serializer. Thanks, nesh. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3795 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/core/serializers/json.py | 2 +- docs/serialization.txt | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 423c44fd3c..99c6ce32f8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -112,6 +112,7 @@ answer newbie questions, and generally made Django that much better: Eric Moritz Robin Munn Nebojša Dorđević + nesh Sam Newman Neal Norwitz oggie rob diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index 72234a624b..15770f160e 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -16,7 +16,7 @@ class Serializer(PythonSerializer): Convert a queryset to JSON. """ def end_serialization(self): - simplejson.dump(self.objects, self.stream, cls=DateTimeAwareJSONEncoder) + simplejson.dump(self.objects, self.stream, cls=DateTimeAwareJSONEncoder, **self.options) def getvalue(self): return self.stream.getvalue() diff --git a/docs/serialization.txt b/docs/serialization.txt index 25199e7a50..694e2d25db 100644 --- a/docs/serialization.txt +++ b/docs/serialization.txt @@ -96,6 +96,21 @@ Django "ships" with a few included serializers: .. _json: http://json.org/ .. _simplejson: http://undefined.org/python/#simplejson +Notes For Specific Serialization Formats +---------------------------------------- + +json +~~~~ + +If you are using UTF-8 (or any other non-ASCII encoding) data with the JSON +serializer, you must pass ``ensure_ascii=False`` as a parameter to the +``serialize()`` call. Otherwise the output will not be encoded correctly. + +For example:: + + json_serializer = serializers.get_serializer("json") + json_serializer.serialize(queryset, ensure_ascii=False, stream=response) + Writing custom serializers ``````````````````````````