瀏覽代碼

#901 support Decimal numbers for JSON serialization

Falko Schindler 2 年之前
父節點
當前提交
c346138820
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      nicegui/json/orjson_wrapper.py

+ 3 - 0
nicegui/json/orjson_wrapper.py

@@ -1,3 +1,4 @@
+from decimal import Decimal
 from typing import Any, Optional, Tuple
 
 import numpy as np
@@ -42,6 +43,8 @@ def _orjson_converter(obj):
     """Custom serializer/converter, e.g. for numpy object arrays."""
     if isinstance(obj, np.ndarray) and obj.dtype == np.object_:
         return obj.tolist()
+    if isinstance(obj, Decimal):
+        return float(obj)
 
 
 class NiceGUIJSONResponse(Response):