generalize JSON serializer (#16733)

This commit is contained in:
Arvid Norberg 2023-10-30 16:50:10 +01:00 committed by GitHub
parent d481ab3a6a
commit 1d55fa894f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
from __future__ import annotations
import dataclasses
import json
from typing import Any
@ -15,7 +14,7 @@ class EnhancedJSONEncoder(json.JSONEncoder):
"""
def default(self, o: Any) -> Any:
if dataclasses.is_dataclass(o):
if hasattr(type(o), "to_json_dict"):
return o.to_json_dict()
elif isinstance(o, WalletType):
return o.name