Module fl_server_ai.notification.serializable¶
View Source
# SPDX-FileCopyrightText: 2024 Benedikt Franke <benedikt.franke@dlr.de>
# SPDX-FileCopyrightText: 2024 Florian Heinrich <florian.heinrich@dlr.de>
#
# SPDX-License-Identifier: Apache-2.0
from dataclasses import asdict, dataclass
from typing import Any
from uuid import UUID
@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()}
Classes¶
Serializable¶
Serializable dataclass
base class which provides a method to serialize the dataclass instance into a dictionary.
View Source
@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()}
Descendants¶
- fl_server_ai.notification.notification.Body
- fl_server_ai.notification.notification.Notification
- fl_server_ai.notification.training.finished.Body
- fl_server_ai.notification.training.round_start.Body
- fl_server_ai.notification.training.start.Body
Methods¶
serialize¶
Serialize the dataclass instance into a dictionary.
UUID fields are converted to strings.
Returns:
Type | Description |
---|---|
dict[str, Any] | The serialized dataclass instance. |