docs: Add notes for kombu.utils.json.register_type (#1660)

Refs #1590
This commit is contained in:
Serhii Tereshchenko 2023-03-02 16:11:03 +02:00 committed by GitHub
parent 6fe50f5985
commit 35f24f1f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -54,6 +54,23 @@ Each option has its advantages and disadvantages.
you need cross-language support, the default setting of `JSON`
is probably your best choice.
If you need support for custom types, you can write serialize/deserialize
functions and register them as follows:
.. code-block:: python
from kombu.utils.json import register_type
from django.db.models import Model
from django.apps import apps
# Allow serialization of django models:
register_type(
Model,
"model",
lambda o: [o._meta.label, o.pk],
lambda o: apps.get_model(o[0]).objects.get(pk=o[1]),
)
`pickle` -- If you have no desire to support any language other than
Python, then using the `pickle` encoding will gain you
the support of all built-in Python data types (except class instances),