Skip to content
Closed
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 @@ -264,9 +264,27 @@ public:

{{/isArray}}{{/isEnum}}{{/vars}}

// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE({{vendorExtensions.modelClassName}},
{{#vars}} {{nameInCamelCase}}{{^-last}},{{/-last}}{{/vars}})
friend void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& o)
{
{{#vars}}
j["{{baseName}}"] = o.{{nameInCamelCase}};
{{/vars}}
}

friend void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& o)
{
{{#requiredVars}}
j.at("{{baseName}}").get_to(o.{{nameInCamelCase}});
{{/requiredVars}}

{{#optionalVars}}
if (j.contains("{{baseName}}") && !j.at("{{baseName}}").is_null())
{
j.at("{{baseName}}").get_to(o.{{nameInCamelCase}});
}
{{/optionalVars}}
}


private:
{{#vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,29 @@ class Address
void setCountry(const std::string& country);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Address,
street, city, zipCode, country)
friend void to_json(nlohmann::json& j, const Address& o)
{
j["street"] = o.street;
j["city"] = o.city;
j["zipCode"] = o.zipCode;
j["country"] = o.country;
}

friend void from_json(const nlohmann::json& j, Address& o)
{
j.at("street").get_to(o.street);
j.at("city").get_to(o.city);

if (j.contains("zipCode") && !j.at("zipCode").is_null())
{
j.at("zipCode").get_to(o.zipCode);
}
if (j.contains("country") && !j.at("country").is_null())
{
j.at("country").get_to(o.country);
}
}


private:
std::string street;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ class Animal
void setType(const std::string& type);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Animal,
name, type)
friend void to_json(nlohmann::json& j, const Animal& o)
{
j["name"] = o.name;
j["type"] = o.type;
}

friend void from_json(const nlohmann::json& j, Animal& o)
{
j.at("name").get_to(o.name);
j.at("type").get_to(o.type);

}


private:
std::string name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,40 @@ class ArrayTypes
void setNestedArray(const std::vector<std::vector<int>>& nestedArray);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ArrayTypes,
stringArray, intArray, objectArray, enumArray, nestedArray)
friend void to_json(nlohmann::json& j, const ArrayTypes& o)
{
j["stringArray"] = o.stringArray;
j["intArray"] = o.intArray;
j["objectArray"] = o.objectArray;
j["enumArray"] = o.enumArray;
j["nestedArray"] = o.nestedArray;
}

friend void from_json(const nlohmann::json& j, ArrayTypes& o)
{

if (j.contains("stringArray") && !j.at("stringArray").is_null())
{
j.at("stringArray").get_to(o.stringArray);
}
if (j.contains("intArray") && !j.at("intArray").is_null())
{
j.at("intArray").get_to(o.intArray);
}
if (j.contains("objectArray") && !j.at("objectArray").is_null())
{
j.at("objectArray").get_to(o.objectArray);
}
if (j.contains("enumArray") && !j.at("enumArray").is_null())
{
j.at("enumArray").get_to(o.enumArray);
}
if (j.contains("nestedArray") && !j.at("nestedArray").is_null())
{
j.at("nestedArray").get_to(o.nestedArray);
}
}


private:
std::vector<std::string> stringArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ class BankAccount
void setBankName(const std::string& bankName);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(BankAccount,
paymentType, accountNumber, bankName)
friend void to_json(nlohmann::json& j, const BankAccount& o)
{
j["paymentType"] = o.paymentType;
j["accountNumber"] = o.accountNumber;
j["bankName"] = o.bankName;
}

friend void from_json(const nlohmann::json& j, BankAccount& o)
{
j.at("paymentType").get_to(o.paymentType);
j.at("accountNumber").get_to(o.accountNumber);
j.at("bankName").get_to(o.bankName);

}


private:
std::string paymentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,32 @@ class Company
void setMetadata(const std::map<std::string, nlohmann::json>& metadata);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Company,
name, headquarters, departments, metadata)
friend void to_json(nlohmann::json& j, const Company& o)
{
j["name"] = o.name;
j["headquarters"] = o.headquarters;
j["departments"] = o.departments;
j["metadata"] = o.metadata;
}

friend void from_json(const nlohmann::json& j, Company& o)
{
j.at("name").get_to(o.name);

if (j.contains("headquarters") && !j.at("headquarters").is_null())
{
j.at("headquarters").get_to(o.headquarters);
}
if (j.contains("departments") && !j.at("departments").is_null())
{
j.at("departments").get_to(o.departments);
}
if (j.contains("metadata") && !j.at("metadata").is_null())
{
j.at("metadata").get_to(o.metadata);
}
}


private:
std::string name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@ class CreatedResponse
void setLocation(const std::string& location);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CreatedResponse,
status, id, location)
friend void to_json(nlohmann::json& j, const CreatedResponse& o)
{
j["status"] = o.status;
j["id"] = o.id;
j["location"] = o.location;
}

friend void from_json(const nlohmann::json& j, CreatedResponse& o)
{
j.at("status").get_to(o.status);
j.at("id").get_to(o.id);

if (j.contains("location") && !j.at("location").is_null())
{
j.at("location").get_to(o.location);
}
}


private:
std::string status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,21 @@ class CreditCard



// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CreditCard,
paymentType, cardNumber, cardType)
friend void to_json(nlohmann::json& j, const CreditCard& o)
{
j["paymentType"] = o.paymentType;
j["cardNumber"] = o.cardNumber;
j["cardType"] = o.cardType;
}

friend void from_json(const nlohmann::json& j, CreditCard& o)
{
j.at("paymentType").get_to(o.paymentType);
j.at("cardNumber").get_to(o.cardNumber);
j.at("cardType").get_to(o.cardType);

}


private:
std::string paymentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,24 @@ class Department
void setEmployees(const std::vector<Employee>& employees);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Department,
name, manager, employees)
friend void to_json(nlohmann::json& j, const Department& o)
{
j["name"] = o.name;
j["manager"] = o.manager;
j["employees"] = o.employees;
}

friend void from_json(const nlohmann::json& j, Department& o)
{
j.at("name").get_to(o.name);
j.at("manager").get_to(o.manager);

if (j.contains("employees") && !j.at("employees").is_null())
{
j.at("employees").get_to(o.employees);
}
}


private:
std::string name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@ class Dog : public Animal
void setBarkVolume(const int& barkVolume);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Dog,
breed, barkVolume)
friend void to_json(nlohmann::json& j, const Dog& o)
{
j["breed"] = o.breed;
j["barkVolume"] = o.barkVolume;
}

friend void from_json(const nlohmann::json& j, Dog& o)
{
j.at("name").get_to(o.name);
j.at("type").get_to(o.type);
j.at("breed").get_to(o.breed);

if (j.contains("barkVolume") && !j.at("barkVolume").is_null())
{
j.at("barkVolume").get_to(o.barkVolume);
}
}


private:
std::string breed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,31 @@ class Employee
void setSkills(const std::vector<std::string>& skills);


// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Employee,
id, name, email, address, skills)
friend void to_json(nlohmann::json& j, const Employee& o)
{
j["id"] = o.id;
j["name"] = o.name;
j["email"] = o.email;
j["address"] = o.address;
j["skills"] = o.skills;
}

friend void from_json(const nlohmann::json& j, Employee& o)
{
j.at("id").get_to(o.id);
j.at("name").get_to(o.name);
j.at("email").get_to(o.email);

if (j.contains("address") && !j.at("address").is_null())
{
j.at("address").get_to(o.address);
}
if (j.contains("skills") && !j.at("skills").is_null())
{
j.at("skills").get_to(o.skills);
}
}


private:
int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,30 @@ class EnumTypes



// JSON serialization using NLOHMANN INTRUSIVE macro (must be inside class to access private members)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(EnumTypes,
stringEnum, numericEnum, statusCode)
friend void to_json(nlohmann::json& j, const EnumTypes& o)
{
j["stringEnum"] = o.stringEnum;
j["numericEnum"] = o.numericEnum;
j["statusCode"] = o.statusCode;
}

friend void from_json(const nlohmann::json& j, EnumTypes& o)
{

if (j.contains("stringEnum") && !j.at("stringEnum").is_null())
{
j.at("stringEnum").get_to(o.stringEnum);
}
if (j.contains("numericEnum") && !j.at("numericEnum").is_null())
{
j.at("numericEnum").get_to(o.numericEnum);
}
if (j.contains("statusCode") && !j.at("statusCode").is_null())
{
j.at("statusCode").get_to(o.statusCode);
}
}


private:
std::optional<StringEnumEnum> stringEnum;
Expand Down
Loading
Loading