Commit b3186283 authored by John Wang's avatar John Wang

fix: uuid json dumps bug

parent 8b6bf432
# -*- coding:utf-8 -*-
import os
import uuid
from datetime import datetime
if not os.environ.get("DEBUG") or os.environ.get("DEBUG").lower() != 'true':
......@@ -183,6 +184,15 @@ if app.config['TESTING']:
print("App is running in TESTING mode")
def uuid_encoder(self, obj):
if isinstance(obj, uuid.UUID):
return str(obj)
raise TypeError(f"Object of type '{type(obj)}' is not JSON serializable")
json.JSONEncoder.default = uuid_encoder
@app.after_request
def after_request(response):
"""Add Version headers to the response."""
......
import json
import uuid
from collections import defaultdict
from typing import Any, List, Optional, Dict
......@@ -235,4 +236,6 @@ class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return super().default(obj)
\ No newline at end of file
elif isinstance(obj, uuid.UUID):
return str(obj)
return super().default(obj)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment