Serializable¶
serializable
¶
Serializable protocol for messages and domain events.
Provides a Serializable protocol that allows types to declare they can be
converted to and from plain dictionaries. This enables generic serialization
infrastructure (JSON, database adapters, event stores) to work with any type
that satisfies the protocol structurally — no base class required.
Serializable
¶
Bases: Protocol
Protocol for serializable objects.
The protocol is structural — any class that defines to_dict and
from_dict with matching signatures satisfies it automatically,
without explicit registration or inheritance.
Source code in src/forging_blocks/infrastructure/serialization/serializable.py
to_dict() -> dict[str, object]
¶
from_dict(data: dict[str, object]) -> Self
classmethod
¶
Create an instance from a dictionary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, object]
|
Dictionary containing the serialised representation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new instance reconstituted from data. |