Skip to content

fl_server_ai.notification.serializable

Classes:

Name Description
Serializable

Serializable dataclass base class which provides a method to serialize the dataclass instance into a dictionary.

Classes

Serializable dataclass

Serializable dataclass base class which provides a method to serialize the dataclass instance into a dictionary.

Methods:

Name Description
__init__
serialize

Serialize the dataclass instance into a dictionary.

Source code in fl_server_ai/notification/serializable.py
@dataclass
class Serializable:
    """
    Serializable `dataclass` base class which provides a method to serialize the dataclass instance into a dictionary.
    """

    def serialize(self) -> dict[str, Any]:
        """
        Serialize the dataclass instance into a dictionary.

        UUID fields are converted to strings.

        Returns:
            dict[str, Any]: The serialized dataclass instance.
        """
        return {key: str(value) if isinstance(value, UUID) else value for key, value in asdict(self).items()}

Functions

__init__
__init__() -> None
serialize
serialize() -> dict[str, Any]

Serialize the dataclass instance into a dictionary.

UUID fields are converted to strings.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The serialized dataclass instance.

Source code in fl_server_ai/notification/serializable.py
def serialize(self) -> dict[str, Any]:
    """
    Serialize the dataclass instance into a dictionary.

    UUID fields are converted to strings.

    Returns:
        dict[str, Any]: The serialized dataclass instance.
    """
    return {key: str(value) if isinstance(value, UUID) else value for key, value in asdict(self).items()}