This commit is contained in:
aaron 2025-02-15 07:28:40 +08:00
parent 62a28014bb
commit 1d1f59bab2

View File

@ -5,11 +5,13 @@ from datetime import datetime
from typing import TypeVar, Generic from typing import TypeVar, Generic
from fastapi import status from fastapi import status
import json import json
from decimal import Decimal
class CustomJSONEncoder(json.JSONEncoder): class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj): def default(self, obj):
if isinstance(obj, datetime): if isinstance(obj, datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S') return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj, Decimal):
return float(obj)
return super().default(obj) return super().default(obj)
class CustomJSONResponse(JSONResponse): class CustomJSONResponse(JSONResponse):