[C++][Pistache] Fixed #2643 (#2653)

* Fixed #2643

Refactored to/from json functions to use universal object serialization method.

* Code review found incorrect indenting and I forgot to remove unused mustache files.

* Removed helpers class because it is not needed anymore.

* Removed helpers package from docs.

* Reverted helper class removal.
This commit is contained in:
SalDiAngelus
2019-04-19 08:00:12 -04:00
committed by sunn
parent cce35d75a4
commit 89eb603c17
37 changed files with 266 additions and 932 deletions

View File

@@ -48,85 +48,71 @@ void User::validate()
// TODO: implement validation
}
nlohmann::json User::toJson() const
void to_json(nlohmann::json& j, const User& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_UsernameIsSet)
{
val["username"] = ModelBase::toJson(m_Username);
}
if(m_FirstNameIsSet)
{
val["firstName"] = ModelBase::toJson(m_FirstName);
}
if(m_LastNameIsSet)
{
val["lastName"] = ModelBase::toJson(m_LastName);
}
if(m_EmailIsSet)
{
val["email"] = ModelBase::toJson(m_Email);
}
if(m_PasswordIsSet)
{
val["password"] = ModelBase::toJson(m_Password);
}
if(m_PhoneIsSet)
{
val["phone"] = ModelBase::toJson(m_Phone);
}
if(m_UserStatusIsSet)
{
val["userStatus"] = m_UserStatus;
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.usernameIsSet())
j["username"] = o.m_Username;
if(o.firstNameIsSet())
j["firstName"] = o.m_FirstName;
if(o.lastNameIsSet())
j["lastName"] = o.m_LastName;
if(o.emailIsSet())
j["email"] = o.m_Email;
if(o.passwordIsSet())
j["password"] = o.m_Password;
if(o.phoneIsSet())
j["phone"] = o.m_Phone;
if(o.userStatusIsSet())
j["userStatus"] = o.m_UserStatus;
}
void User::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, User& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("username") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("username").is_null())
{
setUsername(val.at("username"));
}
if(val.find("firstName") != val.end())
j.at("username").get_to(o.m_Username);
o.m_UsernameIsSet = true;
}
if(!j.at("firstName").is_null())
{
setFirstName(val.at("firstName"));
}
if(val.find("lastName") != val.end())
j.at("firstName").get_to(o.m_FirstName);
o.m_FirstNameIsSet = true;
}
if(!j.at("lastName").is_null())
{
setLastName(val.at("lastName"));
}
if(val.find("email") != val.end())
j.at("lastName").get_to(o.m_LastName);
o.m_LastNameIsSet = true;
}
if(!j.at("email").is_null())
{
setEmail(val.at("email"));
}
if(val.find("password") != val.end())
j.at("email").get_to(o.m_Email);
o.m_EmailIsSet = true;
}
if(!j.at("password").is_null())
{
setPassword(val.at("password"));
}
if(val.find("phone") != val.end())
j.at("password").get_to(o.m_Password);
o.m_PasswordIsSet = true;
}
if(!j.at("phone").is_null())
{
setPhone(val.at("phone"));
}
if(val.find("userStatus") != val.end())
j.at("phone").get_to(o.m_Phone);
o.m_PhoneIsSet = true;
}
if(!j.at("userStatus").is_null())
{
setUserStatus(val.at("userStatus"));
}
j.at("userStatus").get_to(o.m_UserStatus);
o.m_UserStatusIsSet = true;
}
}
int64_t User::getId() const
{
return m_Id;