Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++][Pistache] Add compatibility for nlohmann-json 3.5.0 #3306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o)
void from_json(const nlohmann::json& j, {{classname}}& o)
{
{{#vars}}
{{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.contains("{{baseName}}"))
{{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.find("{{baseName}}") != j.end())
{
j.at("{{baseName}}").get_to(o.m_{{name}});
o.m_{{name}}IsSet = true;
Expand Down
6 changes: 3 additions & 3 deletions samples/server/petstore/cpp-pistache/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ void to_json(nlohmann::json& j, const ApiResponse& o)

void from_json(const nlohmann::json& j, ApiResponse& o)
{
if(j.contains("code"))
if(j.find("code") != j.end())
{
j.at("code").get_to(o.m_Code);
o.m_CodeIsSet = true;
}
if(j.contains("type"))
if(j.find("type") != j.end())
{
j.at("type").get_to(o.m_Type);
o.m_TypeIsSet = true;
}
if(j.contains("message"))
if(j.find("message") != j.end())
{
j.at("message").get_to(o.m_Message);
o.m_MessageIsSet = true;
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/model/Category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Category& o)

void from_json(const nlohmann::json& j, Category& o)
{
if(j.contains("id"))
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(j.contains("name"))
if(j.find("name") != j.end())
{
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/model/Inline_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Inline_object& o)

void from_json(const nlohmann::json& j, Inline_object& o)
{
if(j.contains("name"))
if(j.find("name") != j.end())
{
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
}
if(j.contains("status"))
if(j.find("status") != j.end())
{
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ void to_json(nlohmann::json& j, const Inline_object_1& o)

void from_json(const nlohmann::json& j, Inline_object_1& o)
{
if(j.contains("additionalMetadata"))
if(j.find("additionalMetadata") != j.end())
{
j.at("additionalMetadata").get_to(o.m_AdditionalMetadata);
o.m_AdditionalMetadataIsSet = true;
}
if(j.contains("file"))
if(j.find("file") != j.end())
{
j.at("file").get_to(o.m_file);
o.m_fileIsSet = true;
Expand Down
12 changes: 6 additions & 6 deletions samples/server/petstore/cpp-pistache/model/Order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,32 @@ void to_json(nlohmann::json& j, const Order& o)

void from_json(const nlohmann::json& j, Order& o)
{
if(j.contains("id"))
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(j.contains("petId"))
if(j.find("petId") != j.end())
{
j.at("petId").get_to(o.m_PetId);
o.m_PetIdIsSet = true;
}
if(j.contains("quantity"))
if(j.find("quantity") != j.end())
{
j.at("quantity").get_to(o.m_Quantity);
o.m_QuantityIsSet = true;
}
if(j.contains("shipDate"))
if(j.find("shipDate") != j.end())
{
j.at("shipDate").get_to(o.m_ShipDate);
o.m_ShipDateIsSet = true;
}
if(j.contains("status"))
if(j.find("status") != j.end())
{
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
}
if(j.contains("complete"))
if(j.find("complete") != j.end())
{
j.at("complete").get_to(o.m_Complete);
o.m_CompleteIsSet = true;
Expand Down
8 changes: 4 additions & 4 deletions samples/server/petstore/cpp-pistache/model/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ void to_json(nlohmann::json& j, const Pet& o)

void from_json(const nlohmann::json& j, Pet& o)
{
if(j.contains("id"))
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(j.contains("category"))
if(j.find("category") != j.end())
{
j.at("category").get_to(o.m_Category);
o.m_CategoryIsSet = true;
}
j.at("name").get_to(o.m_Name);
j.at("photoUrls").get_to(o.m_PhotoUrls);
if(j.contains("tags"))
if(j.find("tags") != j.end())
{
j.at("tags").get_to(o.m_Tags);
o.m_TagsIsSet = true;
}
if(j.contains("status"))
if(j.find("status") != j.end())
{
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/model/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Tag& o)

void from_json(const nlohmann::json& j, Tag& o)
{
if(j.contains("id"))
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(j.contains("name"))
if(j.find("name") != j.end())
{
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
Expand Down
16 changes: 8 additions & 8 deletions samples/server/petstore/cpp-pistache/model/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,42 @@ void to_json(nlohmann::json& j, const User& o)

void from_json(const nlohmann::json& j, User& o)
{
if(j.contains("id"))
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(j.contains("username"))
if(j.find("username") != j.end())
{
j.at("username").get_to(o.m_Username);
o.m_UsernameIsSet = true;
}
if(j.contains("firstName"))
if(j.find("firstName") != j.end())
{
j.at("firstName").get_to(o.m_FirstName);
o.m_FirstNameIsSet = true;
}
if(j.contains("lastName"))
if(j.find("lastName") != j.end())
{
j.at("lastName").get_to(o.m_LastName);
o.m_LastNameIsSet = true;
}
if(j.contains("email"))
if(j.find("email") != j.end())
{
j.at("email").get_to(o.m_Email);
o.m_EmailIsSet = true;
}
if(j.contains("password"))
if(j.find("password") != j.end())
{
j.at("password").get_to(o.m_Password);
o.m_PasswordIsSet = true;
}
if(j.contains("phone"))
if(j.find("phone") != j.end())
{
j.at("phone").get_to(o.m_Phone);
o.m_PhoneIsSet = true;
}
if(j.contains("userStatus"))
if(j.find("userStatus") != j.end())
{
j.at("userStatus").get_to(o.m_UserStatus);
o.m_UserStatusIsSet = true;
Expand Down