feat: add JSON custom serializer
This commit is contained in:
+11
-2
@@ -12,6 +12,7 @@ from ecdsa import SECP256k1, SigningKey
|
|||||||
from fastapi import Query
|
from fastapi import Query
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
|
import json
|
||||||
|
|
||||||
from lnbits.db import FilterModel
|
from lnbits.db import FilterModel
|
||||||
from lnbits.helpers import url_for
|
from lnbits.helpers import url_for
|
||||||
@@ -26,6 +27,14 @@ from lnbits.wallets.base import (
|
|||||||
PaymentSuccessStatus,
|
PaymentSuccessStatus,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def json_custom_serialization(_, o):
|
||||||
|
if isinstance(o, datetime):
|
||||||
|
return o.isoformat()
|
||||||
|
raise TypeError(f"Object is not JSON serializable: {o}")
|
||||||
|
|
||||||
|
|
||||||
|
json.JSONEncoder.default = json_custom_serialization
|
||||||
|
|
||||||
|
|
||||||
class BaseWallet(BaseModel):
|
class BaseWallet(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
@@ -279,9 +288,9 @@ class Payment(BaseModel):
|
|||||||
amount: int
|
amount: int
|
||||||
fee: int
|
fee: int
|
||||||
memo: Optional[str]
|
memo: Optional[str]
|
||||||
time: int
|
time: datetime
|
||||||
bolt11: str
|
bolt11: str
|
||||||
expiry: Optional[float]
|
expiry: Optional[datetime]
|
||||||
extra: Optional[dict]
|
extra: Optional[dict]
|
||||||
webhook: Optional[str]
|
webhook: Optional[str]
|
||||||
webhook_status: Optional[int] = None
|
webhook_status: Optional[int] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user