Jump to >

This documentation covers the in-development release of Djblets. You can see the latest stable docs or all previous versions.

djblets.util.serializers

Utilities for serializing content.

class DjbletsJSONEncoder(strip_datetime_ms=True, *args, **kwargs)[source]

A JSON encoder that supports lazy strings, datetimes, and other objects.

This is a specialization of DjangoJSONEncoder the does the following:

  • Evaluates strings translated with gettext_lazy() to real strings.

  • Removes the milliseconds and microseconds from datetimes (unless setting strip_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 Django models with a to_json method via that method.

default(obj)[source]

Encode the object into a JSON-compatible structure.

Parameters

obj (object) – The object to encode.

Returns

A JSON-compatible structure (e.g., a dict, list, py:class:unicode, or bytes object).

Return type

object