From 765d887943f14c48e45b6ce05bab0cd66c780082 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Sep 2012 13:43:26 +0200 Subject: [PATCH] Extend data serialization with JSON --- src/App/PropertyPythonObject.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index 1b8d14652..455ea65f6 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -94,6 +94,9 @@ std::string PropertyPythonObject::toString() const else if (this->object.hasAttr("__dict__")) { dump = this->object.getAttr("__dict__"); } + else { + dump = this->object; + } Py::Tuple args(1); args.setItem(0, dump); @@ -125,9 +128,12 @@ void PropertyPythonObject::fromString(const std::string& repr) Py::Callable state(this->object.getAttr("__setstate__")); state.apply(args); } - else { + else if (this->object.hasAttr("__dict__")) { this->object.setAttr("__dict__", res); } + else { + this->object = res; + } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text @@ -269,6 +275,9 @@ void PropertyPythonObject::Save (Base::Writer &writer) const << " class=\"" << (std::string)name << "\""; } } + else { + writer.Stream() << " json=\"yes\""; + } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text @@ -333,6 +342,9 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader) load_pickle = true; buffer = std::string(what[2].second, end); } + else if (reader.hasAttribute("json")) { + load_json = true; + } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text