Salome HOME
API c++
[modules/gde.git] / projects / GDE_API_CPP / api / src / CommandResultTO.cpp
1 #include "CommandResultTO.hpp"
2 #include "JsonFormatter.hpp"
3
4 gde::CommandResultTO::CommandResultTO(const CommandResultTO& cto)
5   : _code(cto._code), _message(cto._message), _data(cto._data)
6 {
7 }
8
9 gde::CommandResultTO
10 gde::CommandResultTO::fromJson(std::string json)
11 {
12   Poco::JSON::Object::Ptr object = JsonFormatter::parse(json);
13   int code = JsonFormatter::extract<int>(object, "code");
14   std::string message = JsonFormatter::extract<std::string>(object, "message");
15   std::string data = JsonFormatter::extract<std::string>(object, "data");
16   return CommandResultTO(code, message, data);
17 }
18
19 std::string
20 gde::CommandResultTO::toJson()
21 {
22   Poco::JSON::Object obj;
23   obj.set("code", Poco::Dynamic::Var(_code));
24   obj.set("message", Poco::Dynamic::Var(_message));
25   obj.set("data", Poco::Dynamic::Var(_data));
26
27   return JsonFormatter::stringify(obj);
28 }