summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommy Beadle <tbeadle@gmail.com>2016-06-03 14:33:19 -0400
committerTim Graham <timograham@gmail.com>2016-06-07 15:04:30 -0400
commitd22bac99b072abd6b04e4393d355ee6fb614300c (patch)
tree6fea1feee616485d66aa333b40b52c29973936b0
parentdf4382341a0a3201db25d2d82ab86b1cd72ffab1 (diff)
[1.9.x] Fixed #26704 -- Documented DjangoJSONEncoder.
Backport of 729b9452b19b031d3817821128a115d5b2d5caed from master
-rw-r--r--docs/ref/request-response.txt2
-rw-r--r--docs/topics/serialization.txt28
2 files changed, 26 insertions, 4 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 29caf0617e..564a36cf13 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -936,7 +936,7 @@ types of HTTP responses. Like ``HttpResponse``, these subclasses live in
JSON-serializable object.
The ``encoder``, which defaults to
- ``django.core.serializers.json.DjangoJSONEncoder``, will be used to
+ :class:`django.core.serializers.json.DjangoJSONEncoder`, will be used to
serialize the data. See :ref:`JSON serialization
<serialization-formats-json>` for more details about this serializer.
diff --git a/docs/topics/serialization.txt b/docs/topics/serialization.txt
index 75a1eaa9cd..d8b47b0482 100644
--- a/docs/topics/serialization.txt
+++ b/docs/topics/serialization.txt
@@ -253,9 +253,6 @@ Foreign keys just have the PK of the linked object as property value.
ManyToMany-relations are serialized for the model that defines them and are
represented as a list of PKs.
-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
custom :mod:`json` encoder. Something like this will work::
@@ -273,6 +270,31 @@ custom :mod:`json` encoder. Something like this will work::
Also note that GeoDjango provides a :doc:`customized GeoJSON serializer
</ref/contrib/gis/serializers>`.
+``DjangoJSONEncoder``
+~~~~~~~~~~~~~~~~~~~~~
+
+.. class:: django.core.serializers.json.DjangoJSONEncoder
+
+The JSON serializer uses ``DjangoJSONEncoder`` for encoding. A subclass of
+:class:`~json.JSONEncoder`, it handles these additional types:
+
+:class:`~datetime.datetime`
+ A string of the form ``YYYY-MM-DDTHH:mm:ss.sssZ`` or
+ ``YYYY-MM-DDTHH:mm:ss.sss+HH:MM`` as defined in `ECMA-262`_.
+
+:class:`~datetime.date`
+ A string of the form ``YYYY-MM-DD`` as defined in `ECMA-262`_.
+
+:class:`~datetime.time`
+ A string of the form ``HH:MM:ss.sss`` as defined in `ECMA-262`_.
+
+:class:`~decimal.Decimal`, :class:`~uuid.UUID`
+ A string representation of the object.
+
+.. versionchanged:: 1.8.4
+
+ Support for :class:`~uuid.UUID` was added.
+
.. _ecma-262: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
YAML