summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-09-26 20:15:26 +0200
committerClaude Paroz <claude@2xlibre.net>2015-09-27 22:37:27 +0200
commitb7ade645290ecf45530fe7211f8f759fc9cf9971 (patch)
treef28449efe250495afa3b11aa8fce01c85b1df29e /docs
parent87630bc3042da106b29fb1307bb77426f80dcf84 (diff)
Fixed #25468 -- Made DjangoJSONEncoder lazy string aware
Thanks Stavros Korokithakis for the report and Tim Graham for the review.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/1.10.txt6
-rw-r--r--docs/topics/serialization.txt7
2 files changed, 9 insertions, 4 deletions
diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt
index bd32f874d9..66d3828087 100644
--- a/docs/releases/1.10.txt
+++ b/docs/releases/1.10.txt
@@ -162,6 +162,12 @@ Requests and Responses
* ...
+Serialization
+^^^^^^^^^^^^^
+
+* The ``django.core.serializers.json.DjangoJSONEncoder`` now knows how to
+ serialize lazy strings, typically used for translatable content.
+
Signals
^^^^^^^
diff --git a/docs/topics/serialization.txt b/docs/topics/serialization.txt
index e34553699d..2221463210 100644
--- a/docs/topics/serialization.txt
+++ b/docs/topics/serialization.txt
@@ -256,16 +256,15 @@ Date and datetime related types are treated in a special way by the JSON
serializer to make the format compatible with `ECMA-262`_.
Be aware that not all Django output can be passed unmodified to :mod:`json`.
-In particular, :ref:`lazy translation objects <lazy-translations>` need a
-`special encoder`_ written for them. Something like this will work::
+For example, if you have some custom type in an object to be serialized, you'll
+have to write a `special encoder`_ for it. Something like this will work::
- from django.utils.functional import Promise
from django.utils.encoding import force_text
from django.core.serializers.json import DjangoJSONEncoder
class LazyEncoder(DjangoJSONEncoder):
def default(self, obj):
- if isinstance(obj, Promise):
+ if isinstance(obj, YourCustomType):
return force_text(obj)
return super(LazyEncoder, self).default(obj)