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/include/image_upload.hpp b/include/image_upload.hpp
index 330ea9c..aefb27e 100644
--- a/include/image_upload.hpp
+++ b/include/image_upload.hpp
@@ -51,12 +51,10 @@
}
asyncResp->res.result(boost::beast::http::status::bad_request);
- asyncResp->res.jsonValue = {
- {"data",
- {{"description",
- "Version already exists or failed to be extracted"}}},
- {"message", "400 Bad Request"},
- {"status", "error"}};
+ asyncResp->res.jsonValue["data"]["description"] =
+ "Version already exists or failed to be extracted";
+ asyncResp->res.jsonValue["message"] = "400 Bad Request";
+ asyncResp->res.jsonValue["status"] = "error";
};
std::function<void(sdbusplus::message::message&)> callback =
@@ -80,8 +78,9 @@
leaf = path.str;
}
- asyncResp->res.jsonValue = {
- {"data", leaf}, {"message", "200 OK"}, {"status", "ok"}};
+ asyncResp->res.jsonValue["data"] = leaf;
+ asyncResp->res.jsonValue["message"] = "200 OK";
+ asyncResp->res.jsonValue["status"] = "ok";
BMCWEB_LOG_DEBUG << "ending response";
fwUpdateMatcher = nullptr;
}