up stuff
This commit is contained in:
parent
656c3fd414
commit
1c17b57d8a
37 changed files with 2818 additions and 469 deletions
32
oedb/utils/serialization.py
Normal file
32
oedb/utils/serialization.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
"""
|
||||
Serialization utilities for the OpenEventDatabase.
|
||||
Provides JSON serialization functionality for event data.
|
||||
"""
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
class EventEncoder(json.JSONEncoder):
|
||||
"""
|
||||
Custom JSON encoder for event data.
|
||||
Handles datetime objects by converting them to ISO format strings.
|
||||
"""
|
||||
def default(self, o):
|
||||
if isinstance(o, datetime):
|
||||
return o.isoformat()
|
||||
try:
|
||||
return super().default(o)
|
||||
except TypeError:
|
||||
return str(o)
|
||||
|
||||
def dumps(data):
|
||||
"""
|
||||
Serialize data to JSON using the EventEncoder.
|
||||
|
||||
Args:
|
||||
data: The data to serialize.
|
||||
|
||||
Returns:
|
||||
str: The JSON string representation of the data.
|
||||
"""
|
||||
return json.dumps(data, cls=EventEncoder, sort_keys=True, ensure_ascii=False)
|
Loading…
Add table
Add a link
Reference in a new issue