From 5014fbd9e238f19c68c9ce6f94f29a048d79a70e Mon Sep 17 00:00:00 2001 From: StanChan03 Date: Sat, 18 Jan 2025 16:48:47 -0800 Subject: [PATCH] custom object serialization --- lotus/cache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lotus/cache.py b/lotus/cache.py index b5b85c7e..cd306876 100644 --- a/lotus/cache.py +++ b/lotus/cache.py @@ -53,7 +53,10 @@ def serialize(value: Any) -> Any: elif hasattr(value, "dict"): return value.dict() elif hasattr(value, "__dict__"): - return {key: serialize(val) for key, val in vars(value).items() if not key.startswith("_")} + return { + "class_name": type(value).__name__, + "attributes": {k: serialize(v) for k, v in vars(value).items()}, + } else: # For unsupported types, convert to string (last resort) lotus.logger.warning(f"Unsupported type {type(value)} for serialization. Converting to string.")