Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:31

0001 /*
0002  * JSONSerializer.cc
0003  *
0004  *  Created on: Aug 2, 2012
0005  *      Author: aspataru
0006  */
0007 
0008 #include "EventFilter/Utilities/interface/JSONSerializer.h"
0009 
0010 #include <cassert>
0011 
0012 using namespace jsoncollector;
0013 
0014 bool JSONSerializer::serialize(JsonSerializable* pObj, std::string& output) {
0015   assert(pObj != nullptr);
0016 
0017   Json::Value serializeRoot;
0018   pObj->serialize(serializeRoot);
0019 
0020   Json::StyledWriter writer;
0021   output = writer.write(serializeRoot);
0022 
0023   return true;
0024 }
0025 
0026 bool JSONSerializer::deserialize(JsonSerializable* pObj, std::string& input) {
0027   assert(pObj != nullptr);
0028 
0029   Json::Value deserializeRoot;
0030   Json::Reader reader;
0031 
0032   if (!reader.parse(input, deserializeRoot))
0033     return false;
0034 
0035   pObj->deserialize(deserializeRoot);
0036 
0037   return true;
0038 }