🧱 Serialization & Deserialization
By default, Dispytch uses JSON for serializing and deserializing events. This keeps things simple and readable—but you're not stuck with it. If you're sending binary data, need better performance, or just enjoy making things more complicated than they need to be, you can plug in a custom serializer or deserializer.
✍️ Setting a Serializer (Producer Side)
To override the default JSON serializer, pass a serializer instance to your Producer
:
1 2 3 4 5 6 7 |
|
If you don’t explicitly pass one, JSONSerializer()
is used under the hood.
🧩 Setting a Deserializer (Consumer Side)
Same deal for consumers. You can pick how incoming messages are decoded (should be consistent with sending side):
1 2 3 4 5 6 7 |
|
Again, if you don’t set it, Dispytch will default to JSONDeserializer()
.
✨ Writing Your Own
Custom serialization is as simple as implementing a method.
1 2 3 4 5 6 |
|
1 2 3 4 5 6 |
|