diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index e023997..4c963b0 100644
a
|
b
|
from django.core.serializers.python import (
|
16 | 16 | Deserializer as PythonDeserializer, Serializer as PythonSerializer, |
17 | 17 | ) |
18 | 18 | from django.utils import six |
| 19 | from django.utils.functional import Promise |
19 | 20 | from django.utils.timezone import is_aware |
20 | 21 | |
21 | 22 | |
… |
… |
class DjangoJSONEncoder(json.JSONEncoder):
|
111 | 112 | return str(o) |
112 | 113 | elif isinstance(o, uuid.UUID): |
113 | 114 | return str(o) |
| 115 | elif isinstance(o, Promise): |
| 116 | return six.text_type(o) |
114 | 117 | else: |
115 | 118 | return super(DjangoJSONEncoder, self).default(o) |
116 | 119 | |
diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py
index 4239dce..d8d445d 100644
a
|
b
|
import re
|
6 | 6 | |
7 | 7 | from django.core import serializers |
8 | 8 | from django.core.serializers.base import DeserializationError |
9 | | from django.test import TestCase, TransactionTestCase |
| 9 | from django.core.serializers.json import DjangoJSONEncoder |
| 10 | from django.test import SimpleTestCase, TestCase, TransactionTestCase |
| 11 | from django.utils.translation import override, ugettext_lazy |
10 | 12 | |
11 | 13 | from .models import Score |
12 | 14 | from .tests import SerializersTestBase, SerializersTransactionTestBase |
… |
… |
class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
|
271 | 273 | "name": "Agnes" |
272 | 274 | } |
273 | 275 | }]""" |
| 276 | |
| 277 | |
| 278 | class DjangoJSONEncoderTests(SimpleTestCase): |
| 279 | def test_lazy_string_encoding(self): |
| 280 | self.assertEqual( |
| 281 | json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), |
| 282 | '{"lang": "French"}' |
| 283 | ) |
| 284 | with override('fr'): |
| 285 | self.assertEqual( |
| 286 | json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), |
| 287 | '{"lang": "Fran\\u00e7ais"}' |
| 288 | ) |