Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/server/engine-lib/engLib/python/pyjson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ class pyjson {
}
return value;
}

// Pydantic v2 model — call .model_dump() to get a plain dict
if (py::hasattr(obj, "model_dump")) {
py::dict d = obj.attr("model_dump")();
return dictToJson(d);
}
// Pydantic v1 model — call .dict() to get a plain dict
if (py::hasattr(obj, "dict") && py::hasattr(obj, "__fields__")) {
py::dict d = obj.attr("dict")();
return dictToJson(d);
}
// Any callable (function, method, builtin, partial, etc.) — not serializable
if (PyCallable_Check(obj.ptr())) {
json::Value value{"<method>"};
return value;
}

throw std::runtime_error(
"dictToJson not implemented for this type of object: " +
py::repr(obj).cast<std::string>());
Expand Down
Loading