Example #1
0
void Post::Deserialize(Json::Value& root) {
    // General Post
    id_             = root.get("id", "").asString();
    entity_         = root.get("entity", "").asString();
    published_at_   = root.get("published_at", "").asString();
    received_at_    = root.get("received_at", "").asString();
    type_           = root.get("type", "").asString();
    if(type_.find("#") != std::string::npos)
        base_type_ = type_.substr(0, type_.find("#")+1);

    jsn::DeserializeObject(&version_, root["version"]);
    jsn::DeserializeIntoVector(root["licenses"], licenses_);
    jsn::DeserializeObjectValueIntoMap(root["content"], content_);
    
    // Deserialize this into an array of objects
    Json::Value jsn_attch(Json::arrayValue);
    jsn_attch = root["attachments"];

    if(jsn_attch.size() > 0) {
        Json::ValueIterator itr = jsn_attch.begin();           
        for(; itr != jsn_attch.end(); itr++) {
            //Attachment* pAtch = new Attachment;
            Attachment attch;
            Json::Value aobj(Json::objectValue);
            aobj = (*itr);

            if(aobj.isObject()) {
                if(aobj.size() >= 4) {
                    Json::ValueIterator ii = aobj.begin();
                    for(; ii != aobj.end(); ii++) {
                        attch.AssignKeyValue(ii.key().asString(), (*ii));
                    }
                }
            }
            PushBackAttachment(attch);
        }
    }

    Json::Value mentions_array(Json::arrayValue);
    mentions_array = root["mentions"];

    if(mentions_array.size() > 0) {
        Json::ValueIterator itr = mentions_array.begin();
        for(;itr != mentions_array.end(); itr++) {
            Mention mention;
            Json::Value mobj;
            mobj = (*itr);

            if(mobj.isObject()) {
                jsn::DeserializeObject(&mention, mobj);
                PushBackMention(mention);
            }
        }
    }

    if(root.isMember("app")) {
        tent_app_.Deserialize(root["app"]);
    }
    else {
        std::cout<<" post has no app " << std::endl;
    }


    jsn::DeserializeObjectValueIntoMap(root["views"], views_);
    jsn::DeserializeObject(&permissions_,root["permissions"]);
}