djblets.util.serializers¶
Utilities for serializing content.
- class DjbletsJSONEncoder(strip_datetime_ms: bool = True, *args, **kwargs)[source]¶
Bases:
DjangoJSONEncoder
A JSON encoder that supports lazy strings, datetimes, and other objects.
This is a specialization of
DjangoJSONEncoder
the does the following:Removes the milliseconds and microseconds from
datetimes
(unless settingstrip_datetime_ms=False
when constructing the encoder). This is to help keep timestamps from appearing too new when compared against data coming from a MySQL database (which historically, and by default, chops off milliseconds).Serializes objects (including
Django models
with) containing ato_json
method.
- __annotations__ = {'strip_datetime_ms': 'bool'}¶