mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #15091 -- Allowed passing custom encoder to JSON serializer.
This commit is contained in:
committed by
Tim Graham
parent
6bf7964023
commit
c1b6f554e4
@@ -265,6 +265,17 @@ work::
|
||||
return force_text(obj)
|
||||
return super(LazyEncoder, self).default(obj)
|
||||
|
||||
You can then pass ``cls=LazyEncoder`` to the ``serializers.serialize()``
|
||||
function::
|
||||
|
||||
from django.core.serializers import serialize
|
||||
|
||||
serialize('json', SomeModel.objects.all(), cls=LazyEncoder)
|
||||
|
||||
.. versionchanged:: 1.11
|
||||
|
||||
The ability to use a custom encoder using ``cls=...`` was added.
|
||||
|
||||
Also note that GeoDjango provides a :doc:`customized GeoJSON serializer
|
||||
</ref/contrib/gis/serializers>`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user