Update dependencies and fix deprecations
This commit is contained in:
parent
0d4fbef13d
commit
19d264a03b
8 changed files with 154 additions and 131 deletions
|
|
@ -1,29 +0,0 @@
|
|||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from flask.json import JSONEncoder as _FlaskJSONEncoder
|
||||
|
||||
__all__ = [
|
||||
'JSONEncoder',
|
||||
]
|
||||
|
||||
|
||||
class JSONEncoder(_FlaskJSONEncoder):
|
||||
"""
|
||||
Custom JSON encoder built on top of the Flask JSONEncoder class.
|
||||
"""
|
||||
|
||||
def default(self, obj: Any) -> Any:
|
||||
"""
|
||||
Convert any object to a JSON serializable type.
|
||||
"""
|
||||
# Convert datetimes to ISO format without microseconds (e.g. '2022-01-02T10:20:30+00:00')
|
||||
if isinstance(obj, datetime):
|
||||
return obj.isoformat(timespec='seconds')
|
||||
|
||||
# Use to_dict() method on objects that have it
|
||||
if hasattr(obj, 'to_dict'):
|
||||
return obj.to_dict()
|
||||
|
||||
# Fallback to the Flask JSONEncoder
|
||||
return super().default(obj)
|
||||
Loading…
Add table
Add a link
Reference in a new issue