summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhii Tereshchenko <serg.partizan@gmail.com>2023-03-02 16:11:03 +0200
committerGitHub <noreply@github.com>2023-03-02 16:11:03 +0200
commit35f24f1f01c7895926a990be0616a4582374749a (patch)
tree69987b31dba177f07e38df90c3509a73357e104e
parent6fe50f5985b01c1f9b172f740c51400540bfc92d (diff)
downloadkombu-35f24f1f01c7895926a990be0616a4582374749a.tar.gz
docs: Add notes for kombu.utils.json.register_type (#1660)
Refs #1590
-rw-r--r--docs/userguide/serialization.rst17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/userguide/serialization.rst b/docs/userguide/serialization.rst
index 86eb04bb..f8523e69 100644
--- a/docs/userguide/serialization.rst
+++ b/docs/userguide/serialization.rst
@@ -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),