[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

@@ -38,45 +38,36 @@ void ApiResponse::validate()
// TODO: implement validation
}
nlohmann::json ApiResponse::toJson() const
void to_json(nlohmann::json& j, const ApiResponse& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_CodeIsSet)
{
val["code"] = m_Code;
}
if(m_TypeIsSet)
{
val["type"] = ModelBase::toJson(m_Type);
}
if(m_MessageIsSet)
{
val["message"] = ModelBase::toJson(m_Message);
}
return val;
j = nlohmann::json();
if(o.codeIsSet())
j["code"] = o.m_Code;
if(o.typeIsSet())
j["type"] = o.m_Type;
if(o.messageIsSet())
j["message"] = o.m_Message;
}
void ApiResponse::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, ApiResponse& o)
{
if(val.find("code") != val.end())
if(!j.at("code").is_null())
{
setCode(val.at("code"));
}
if(val.find("type") != val.end())
j.at("code").get_to(o.m_Code);
o.m_CodeIsSet = true;
}
if(!j.at("type").is_null())
{
setType(val.at("type"));
}
if(val.find("message") != val.end())
j.at("type").get_to(o.m_Type);
o.m_TypeIsSet = true;
}
if(!j.at("message").is_null())
{
setMessage(val.at("message"));
}
j.at("message").get_to(o.m_Message);
o.m_MessageIsSet = true;
}
}
int32_t ApiResponse::getCode() const
{
return m_Code;