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

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

friend void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& o)
{
{{^parent}}
j = nlohmann::json::object();
{{/parent}}
{{#parent}}
// Serialize inherited properties via the parent's serializer
to_json(j, static_cast<const {{parent}}&>(o));
{{/parent}}
{{#vars}}
j["{{baseName}}"] = o.{{nameInCamelCase}};
{{/vars}}
}

friend void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& o)
{
if (!j.is_object())
friend inline void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& o)
{
throw nlohmann::json::type_error::create(302, "{{vendorExtensions.modelClassName}} must be a JSON object", &j);
{{^parent}}
j = nlohmann::json::object();
{{/parent}}
{{#parent}}
// Serialize inherited properties via the parent's serializer
to_json(j, static_cast<const {{parent}}&>(o));
{{/parent}}
{{#vars}}
j["{{baseName}}"] = o.{{nameInCamelCase}};
{{/vars}}
}
{{#parent}}
// Deserialize inherited properties via the parent's deserializer
from_json(j, static_cast<{{parent}}&>(o));
{{/parent}}
{{#vars}}
{{#required}}
j.at("{{baseName}}").get_to(o.{{nameInCamelCase}});
{{/required}}
{{^required}}
{{! Present null reaches get_to (resets std::optional, rejected for non-nullable); skipped only for nullable members that cannot hold null }}
if (j.contains("{{baseName}}"){{#isNullable}}{{^vendorExtensions.isOptionalEnum}} && !j.at("{{baseName}}").is_null(){{/vendorExtensions.isOptionalEnum}}{{/isNullable}})

friend inline void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& o)
{
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "{{vendorExtensions.modelClassName}} must be a JSON object", &j);
}
{{#parent}}
// Deserialize inherited properties via the parent's deserializer
from_json(j, static_cast<{{parent}}&>(o));
{{/parent}}
{{#vars}}
{{#required}}
j.at("{{baseName}}").get_to(o.{{nameInCamelCase}});
{{/required}}
{{^required}}
{{! Present null reaches get_to (resets std::optional, rejected for non-nullable); skipped only for nullable members that cannot hold null }}
if (j.contains("{{baseName}}"){{#isNullable}}{{^vendorExtensions.isOptionalEnum}} && !j.at("{{baseName}}").is_null(){{/vendorExtensions.isOptionalEnum}}{{/isNullable}})
{
j.at("{{baseName}}").get_to(o.{{nameInCamelCase}});
}
{{/required}}
{{/vars}}
}
{{/required}}
{{/vars}}
}


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


friend void to_json(nlohmann::json& j, const Address& o)
{
j = nlohmann::json::object();
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)
{
if (!j.is_object())
friend inline void to_json(nlohmann::json& j, const Address& o)
{
throw nlohmann::json::type_error::create(302, "Address must be a JSON object", &j);
j = nlohmann::json::object();
j["street"] = o.street;
j["city"] = o.city;
j["zipCode"] = o.zipCode;
j["country"] = o.country;
}
j.at("street").get_to(o.street);
j.at("city").get_to(o.city);
if (j.contains("zipCode"))
{
j.at("zipCode").get_to(o.zipCode);
}
if (j.contains("country"))

friend inline void from_json(const nlohmann::json& j, Address& o)
{
j.at("country").get_to(o.country);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "Address must be a JSON object", &j);
}
j.at("street").get_to(o.street);
j.at("city").get_to(o.city);
if (j.contains("zipCode"))
{
j.at("zipCode").get_to(o.zipCode);
}
if (j.contains("country"))
{
j.at("country").get_to(o.country);
}
}
}


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


friend void to_json(nlohmann::json& j, const Animal& o)
{
j = nlohmann::json::object();
j["name"] = o.name;
j["type"] = o.type;
}
friend inline void to_json(nlohmann::json& j, const Animal& o)
{
j = nlohmann::json::object();
j["name"] = o.name;
j["type"] = o.type;
}

friend void from_json(const nlohmann::json& j, Animal& o)
{
if (!j.is_object())
friend inline void from_json(const nlohmann::json& j, Animal& o)
{
throw nlohmann::json::type_error::create(302, "Animal must be a JSON object", &j);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "Animal must be a JSON object", &j);
}
j.at("name").get_to(o.name);
j.at("type").get_to(o.type);
}
j.at("name").get_to(o.name);
j.at("type").get_to(o.type);
}


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


friend void to_json(nlohmann::json& j, const ArrayTypes& o)
{
j = nlohmann::json::object();
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.is_object())
{
throw nlohmann::json::type_error::create(302, "ArrayTypes must be a JSON object", &j);
}
if (j.contains("stringArray"))
{
j.at("stringArray").get_to(o.stringArray);
}
if (j.contains("intArray"))
friend inline void to_json(nlohmann::json& j, const ArrayTypes& o)
{
j.at("intArray").get_to(o.intArray);
j = nlohmann::json::object();
j["stringArray"] = o.stringArray;
j["intArray"] = o.intArray;
j["objectArray"] = o.objectArray;
j["enumArray"] = o.enumArray;
j["nestedArray"] = o.nestedArray;
}
if (j.contains("objectArray"))
{
j.at("objectArray").get_to(o.objectArray);
}
if (j.contains("enumArray"))
{
j.at("enumArray").get_to(o.enumArray);
}
if (j.contains("nestedArray"))

friend inline void from_json(const nlohmann::json& j, ArrayTypes& o)
{
j.at("nestedArray").get_to(o.nestedArray);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "ArrayTypes must be a JSON object", &j);
}
if (j.contains("stringArray"))
{
j.at("stringArray").get_to(o.stringArray);
}
if (j.contains("intArray"))
{
j.at("intArray").get_to(o.intArray);
}
if (j.contains("objectArray"))
{
j.at("objectArray").get_to(o.objectArray);
}
if (j.contains("enumArray"))
{
j.at("enumArray").get_to(o.enumArray);
}
if (j.contains("nestedArray"))
{
j.at("nestedArray").get_to(o.nestedArray);
}
}
}


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


friend void to_json(nlohmann::json& j, const BankAccount& o)
{
j = nlohmann::json::object();
j["paymentType"] = o.paymentType;
j["accountNumber"] = o.accountNumber;
j["bankName"] = o.bankName;
}
friend inline void to_json(nlohmann::json& j, const BankAccount& o)
{
j = nlohmann::json::object();
j["paymentType"] = o.paymentType;
j["accountNumber"] = o.accountNumber;
j["bankName"] = o.bankName;
}

friend void from_json(const nlohmann::json& j, BankAccount& o)
{
if (!j.is_object())
friend inline void from_json(const nlohmann::json& j, BankAccount& o)
{
throw nlohmann::json::type_error::create(302, "BankAccount must be a JSON object", &j);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "BankAccount must be a JSON object", &j);
}
j.at("paymentType").get_to(o.paymentType);
j.at("accountNumber").get_to(o.accountNumber);
j.at("bankName").get_to(o.bankName);
}
j.at("paymentType").get_to(o.paymentType);
j.at("accountNumber").get_to(o.accountNumber);
j.at("bankName").get_to(o.bankName);
}


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


friend void to_json(nlohmann::json& j, const Company& o)
{
j = nlohmann::json::object();
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)
{
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "Company must be a JSON object", &j);
}
j.at("name").get_to(o.name);
if (j.contains("headquarters"))
friend inline void to_json(nlohmann::json& j, const Company& o)
{
j.at("headquarters").get_to(o.headquarters);
j = nlohmann::json::object();
j["name"] = o.name;
j["headquarters"] = o.headquarters;
j["departments"] = o.departments;
j["metadata"] = o.metadata;
}
if (j.contains("departments"))
{
j.at("departments").get_to(o.departments);
}
if (j.contains("metadata"))

friend inline void from_json(const nlohmann::json& j, Company& o)
{
j.at("metadata").get_to(o.metadata);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "Company must be a JSON object", &j);
}
j.at("name").get_to(o.name);
if (j.contains("headquarters"))
{
j.at("headquarters").get_to(o.headquarters);
}
if (j.contains("departments"))
{
j.at("departments").get_to(o.departments);
}
if (j.contains("metadata"))
{
j.at("metadata").get_to(o.metadata);
}
}
}


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


friend void to_json(nlohmann::json& j, const CreatedResponse& o)
{
j = nlohmann::json::object();
j["status"] = o.status;
j["id"] = o.id;
j["location"] = o.location;
}

friend void from_json(const nlohmann::json& j, CreatedResponse& o)
{
if (!j.is_object())
friend inline void to_json(nlohmann::json& j, const CreatedResponse& o)
{
throw nlohmann::json::type_error::create(302, "CreatedResponse must be a JSON object", &j);
j = nlohmann::json::object();
j["status"] = o.status;
j["id"] = o.id;
j["location"] = o.location;
}
j.at("status").get_to(o.status);
j.at("id").get_to(o.id);
if (j.contains("location"))

friend inline void from_json(const nlohmann::json& j, CreatedResponse& o)
{
j.at("location").get_to(o.location);
if (!j.is_object())
{
throw nlohmann::json::type_error::create(302, "CreatedResponse must be a JSON object", &j);
}
j.at("status").get_to(o.status);
j.at("id").get_to(o.id);
if (j.contains("location"))
{
j.at("location").get_to(o.location);
}
}
}


private:
Expand Down
Loading
Loading