diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index 9da8993ee6..a475858205 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -16,6 +16,7 @@ from django.core.serializers.python import ( Deserializer as PythonDeserializer, Serializer as PythonSerializer, ) from django.utils import six +from django.utils.deprecation import CallableBool from django.utils.duration import duration_iso_string from django.utils.functional import Promise from django.utils.timezone import is_aware @@ -117,5 +118,7 @@ class DjangoJSONEncoder(json.JSONEncoder): return str(o) elif isinstance(o, Promise): return six.text_type(o) + elif isinstance(o, CallableBool): + return bool(o) else: return super(DjangoJSONEncoder, self).default(o) diff --git a/docs/releases/1.11.2.txt b/docs/releases/1.11.2.txt index a15d4272ec..e1cd939fa0 100644 --- a/docs/releases/1.11.2.txt +++ b/docs/releases/1.11.2.txt @@ -29,3 +29,6 @@ Bugfixes * Fixed a regression where ``Model._state.adding`` wasn't set correctly on multi-table inheritance parent models after saving a child model (:ticket:`28210`). + +* Allowed ``DjangoJSONEncoder`` to serialize + ``django.utils.deprecation.CallableBool`` (:ticket:`28230`). diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py index b191ce6644..391523ae33 100644 --- a/tests/serializers/test_json.py +++ b/tests/serializers/test_json.py @@ -12,6 +12,7 @@ from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.test import SimpleTestCase, TestCase, TransactionTestCase from django.test.utils import isolate_apps +from django.utils.deprecation import CallableFalse, CallableTrue from django.utils.translation import override, ugettext_lazy from .models import Score @@ -315,3 +316,7 @@ class DjangoJSONEncoderTests(SimpleTestCase): json.dumps({'duration': duration}, cls=DjangoJSONEncoder), '{"duration": "P0DT00H00M00S"}' ) + + def test_callable_bool(self): + self.assertEqual(json.dumps(CallableTrue, cls=DjangoJSONEncoder), 'true') + self.assertEqual(json.dumps(CallableFalse, cls=DjangoJSONEncoder), 'false')