Remove brace initialization of json objects
Brace initialization of json objects, while quite interesting from an
academic sense, are very difficult for people to grok, and lead to
inconsistencies. This patchset aims to remove a majority of them in
lieu of operator[]. Interestingly, this saves about 1% of the binary
size of bmcweb.
This also has an added benefit that as a design pattern, we're never
constructing a new object, then moving it into place, we're always
adding to the existing object, which in the future _could_ make things
like OEM schemas or properties easier, as there's no case where we're
completely replacing the response object.
Tested:
Ran redfish service validator. No new failures.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iae409b0a40ddd3ae6112cb2d52c6f6ab388595fe
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 6c55f75..58499a5 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -113,8 +113,9 @@
nlohmann::json ret = nlohmann::json::array();
for (const std::string* uid : sessionIds)
{
- ret.push_back(
- {{"@odata.id", "/redfish/v1/SessionService/Sessions/" + *uid}});
+ nlohmann::json::object_t session;
+ session["@odata.id"] = "/redfish/v1/SessionService/Sessions/" + *uid;
+ ret.push_back(std::move(session));
}
return ret;
}
@@ -245,8 +246,8 @@
persistent_data::SessionStore::getInstance().getTimeoutInSeconds();
asyncResp->res.jsonValue["ServiceEnabled"] = true;
- asyncResp->res.jsonValue["Sessions"] = {
- {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
+ asyncResp->res.jsonValue["Sessions"]["@odata.id"] =
+ "/redfish/v1/SessionService/Sessions";
}
inline void handleSessionServicePatch(