diff options
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/serialization.txt | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/docs/topics/serialization.txt b/docs/topics/serialization.txt index 4793abfa1e..e176cd9ae0 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`. For example, if you have some custom type in an object to be serialized, you'll have to write a custom :mod:`json` encoder for it. Something like this will @@ -273,6 +270,31 @@ 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`, ``Promise`` (``django.utils.functional.lazy()`` objects), :class:`~uuid.UUID` + A string representation of the object. + +.. versionchanged:: 1.10 + + Support for ``Promise`` was added. + .. _ecma-262: http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 YAML |
