.homeworks/hw5/Post.cpp
Json::Value Post::toJson()
{
    Json::Value myv;
    myv["id"] = this->getID();
    myv["from"] = this->author->toJson();
    
    // call toJson() of every objects recursively
    // convert receivers to json
    int i = 0;  // counter of the loop
    for (auto ptr: *this->receivers)
        myv["to"]["data"][i++] = ptr->toJson();
    myv["to"]["count"] = (int)this->receivers->size();

    myv["message"] = this->message->toString();
    
    // convert links to json
    i = 0;
    for (auto ptr: *this->links)
        myv["links"]["data"][i++] = ptr->toJson();
    myv["links"]["count"] = (int)this->links->size();
    
    // convert actions to data
    i = 0;
    for (auto ptr: *this->actions)
        myv["actions"]["data"][i++] = ptr->toJson();
    myv["actions"]["count"] = (int)this->actions->size();
    
    // JvTime is from the professor;
    // this is a little different because getTimeString()
    // returns a pointer to a string
    myv["created_time"] = *this->created_time->getTimeString();
    myv["updated_time"] = *this->updated_time->getTimeString();
    
    // convert reactions to json
    i = 0;
    for (auto ptr: *this->reactions)
        myv["reactions"]["data"][i++] = ptr->toJson();
    myv["reactions"]["count"] = (int)this->reactions->size();
    
    // convert comments to json
    i = 0;
    for (auto ptr: *this->comments)
       myv["comments"]["data"][i++] = ptr.second->toJson();
    myv["comments"]["count"] = (int)this->comments->size();

    myv["is_published"] = this->is_published;
    return myv;

}
/* the top level toJson() function
 * calls toJson() of other class,
 * convert the whole Post to Json format */
the top level toJson() function
calls toJson() of other class,
convert the whole Post to Json format
the top level toJson () function calls toJson () of other class convert the whole Post to Json format
Json::Value Post::toJson()
{
    Json::Value myv;
    myv["id"] = this->getID();
    myv["from"] = this->author->toJson();
    int i = 0;  
    for (auto ptr: *this->receivers)
        myv["to"]["data"][i++] = ptr->toJson();
    myv["to"]["count"] = (int)this->receivers->size();
    myv["message"] = this->message->toString();
    i = 0;
    for (auto ptr: *this->links)
        myv["links"]["data"][i++] = ptr->toJson();
    myv["links"]["count"] = (int)this->links->size();
    i = 0;
    for (auto ptr: *this->actions)
        myv["actions"]["data"][i++] = ptr->toJson();
    myv["actions"]["count"] = (int)this->actions->size();
    myv["created_time"] = *this->created_time->getTimeString();
    myv["updated_time"] = *this->updated_time->getTimeString();
    i = 0;
    for (auto ptr: *this->reactions)
        myv["reactions"]["data"][i++] = ptr->toJson();
    myv["reactions"]["count"] = (int)this->reactions->size();
    i = 0;
    for (auto ptr: *this->comments)
       myv["comments"]["data"][i++] = ptr.second->toJson();
    myv["comments"]["count"] = (int)this->comments->size();
    myv["is_published"] = this->is_published;
    return myv;
}
Json :: Value Post :: toJson ( ) { Json :: Value myv ; myv [ " " ] = this -> getID ( ) ; myv [ " " ] = this -> author -> toJson ( ) ; int i = 0 ; for ( auto ptr : * this -> receivers ) myv [ " " ] [ " " ] [ i ++ ] = ptr -> toJson ( ) ; myv [ " " ] [ " " ] = ( int ) this -> receivers -> size ( ) ; myv [ " " ] = this -> message -> toString ( ) ; i = 0 ; for ( auto ptr : * this -> links ) myv [ " " ] [ " " ] [ i ++ ] = ptr -> toJson ( ) ; myv [ " " ] [ " " ] = ( int ) this -> links -> size ( ) ; i = 0 ; for ( auto ptr : * this -> actions ) myv [ " " ] [ " " ] [ i ++ ] = ptr -> toJson ( ) ; myv [ " " ] [ " " ] = ( int ) this -> actions -> size ( ) ; myv [ " " ] = * this -> created_time -> getTimeString ( ) ; myv [ " " ] = * this -> updated_time -> getTimeString ( ) ; i = 0 ; for ( auto ptr : * this -> reactions ) myv [ " " ] [ " " ] [ i ++ ] = ptr -> toJson ( ) ; myv [ " " ] [ " " ] = ( int ) this -> reactions -> size ( ) ; i = 0 ; for ( auto ptr : * this -> comments ) myv [ " " ] [ " " ] [ i ++ ] = ptr . second -> toJson ( ) ; myv [ " " ] [ " " ] = ( int ) this -> comments -> size ( ) ; myv [ " " ] = this -> is_published ; return myv ; }
the top level toJson() function
 calls toJson() of other class,
 convert the whole Post to Json format
the top level toJson () function calls toJson () of other class convert the whole Post to Json format
// call toJson() of every objects recursively // convert receivers to json // counter of the loop // convert links to json // convert actions to data // JvTime is from the professor; // this is a little different because getTimeString() // returns a pointer to a string // convert reactions to json // convert comments to json