Skip to content

Commit

Permalink
custom object serialization
Browse files Browse the repository at this point in the history
StanChan03 committed Jan 19, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 17b8d63 commit 5014fbd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lotus/cache.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 5014fbd

Please sign in to comment.