This commit is contained in:
Tykayn 2025-09-15 23:25:11 +02:00 committed by tykayn
parent 656c3fd414
commit 1c17b57d8a
37 changed files with 2818 additions and 469 deletions

View 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)