static std::string serialized;
Json::Value jsonRoot;
- Json::StyledWriter writer;
job->jobInfo->toJson(jsonRoot);
- serialized = writer.write(jsonRoot);
+ serialized = jsonRoot.toStyledString();
return serialized.c_str();
}
static std::string serialized;
Json::Value jsonRoot;
- Json::StyledWriter writer;
job_context->jobContext->toJson(jsonRoot);
- serialized = writer.write(jsonRoot);
+ serialized = jsonRoot.toStyledString();
return serialized.c_str();
}
g_variant_get(methodCall.getParam(), "(&s&s)", &uri, &payload);
IF_FAIL_THROW(uri && payload, E_PARAM);
- try {
- Json::Reader reader;
- reader.parse(payload, data);
- } catch (const Json::Exception& e) {
- _E("Exception: %s", e.what());
+ std::string errors;
+ Json::CharReaderBuilder builder;
+ Json::CharReader *reader = builder.newCharReader();
+ bool result= reader->parse(payload, payload + strlen(payload), &data, &errors);
+ delete reader;
+ if (result == false) {
+ _E("parse Error(%s)", errors.c_str());
throw E_PARAM;
}
Json::Value jsonRoot;
toJson(jsonRoot);
- Json::FastWriter fastWriter;
- fastWriter.omitEndingLineFeed();
+ Json::StreamWriterBuilder builder;
+ builder["indentation"] = "";
- return fastWriter.write(jsonRoot);
+ return Json::writeString(builder, jsonRoot);
}
void JobInfo::toJson(Json::Value& jsonRoot) const
JobInfo* JobInfo::deserialize(const std::string& serializedStr)
{
- Json::Reader reader;
Json::Value jsonRoot;
JobInfo* job = NULL;
try {
- if (reader.parse(serializedStr, jsonRoot)) {
+ std::string errors;
+ Json::CharReaderBuilder builder;
+ std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+
+ if (reader->parse(serializedStr.c_str(), serializedStr.c_str() + serializedStr.size(), &jsonRoot, &errors)) {
JobInfo::Type type = static_cast<JobInfo::Type>(jsonRoot[KEY_JOB_TYPE].asInt());
if (type == JobInfo::Type::PERIODIC) {
job = new PeriodicJobInfo(jsonRoot, serializedStr);