Files
clan-core/pkgs/clan-cli/clan_cli/jsonrpc.py
Qubasa 26ff5aa1e1 clan-cli: Ignore new type hints in api/serde.py
clan-cli: Ignore new type hints in api/serde.py

clan-cli: Ignore new type hints in api/serde.py

clan-cli: Ignore new type hints in api/serde.py
2025-01-06 20:14:28 +01:00

16 lines
502 B
Python

import dataclasses
import json
from typing import Any
class ClanJSONEncoder(json.JSONEncoder):
def default(self, o: Any) -> Any:
# Check if the object has a to_json method
if hasattr(o, "to_json") and callable(o.to_json):
return o.to_json()
# Check if the object is a dataclass
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o) # type: ignore
# Otherwise, use the default serialization
return super().default(o)