clan-core/pkgs/clan-cli/clan_cli/jsonrpc.py
Qubasa f4f3176374
Some checks failed
checks / check-links (pull_request) Successful in 21s
checks / checks-impure (pull_request) Successful in 2m0s
checks / checks (pull_request) Failing after 4m7s
clan-vm-manager: Fix ClanUrl not pickable
2024-03-08 23:23:18 +07:00

16 lines
488 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
elif dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
# Otherwise, use the default serialization
return super().default(o)