Source code for nqs_sdk.utils.json_decimal_encoder
import json
from decimal import Decimal
from typing import Any, Union
[docs]
class DecimalEncoder(json.JSONEncoder):
[docs]
def default(self, obj: Any) -> Union[float, str, Any]:
if isinstance(obj, Decimal):
return float(obj)
# Handle other non-serializable objects by converting to string
try:
return super().default(obj)
except TypeError:
return str(obj)