diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-07 00:30:49 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-11 19:02:48 +0300 |
commit | 76b038f20fed54ff61450a175160dc0af21b3cf9 (patch) | |
tree | 43be8a26915ebe79b0ecf94806ce30b4a305786e /redfish-core | |
parent | 665e7602d5580dfe69a9686f35ef40f8f64673df (diff) | |
download | bmcweb-76b038f20fed54ff61450a175160dc0af21b3cf9.tar.xz |
Fix object type in json utils
This code accidentally makes a copy, given that getJsonObject returns a
std::optional<nlohmann::json::object_t> which is then loaded into a
std::optional<nlohmann::json>. Because nlohmann::json is implicitly
constructible from an object_t, this code works and compiles, but we
shouldn't need the intermediate object at all.
Change the code to simply load the value as object_t.
Tested: Unit tests pass. Good coverage.
Change-Id: Ic57953e66958e69a1233e18a5bbd980405cac58e
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp index feb4e5460f..df0c86ebb0 100644 --- a/redfish-core/include/utils/json_utils.hpp +++ b/redfish-core/include/utils/json_utils.hpp @@ -659,21 +659,19 @@ template <typename... UnpackTypes> bool readJsonPatch(const crow::Request& req, crow::Response& res, std::string_view key, UnpackTypes&&... in) { - std::optional<nlohmann::json> jsonRequest = readJsonPatchHelper(req, res); + std::optional<nlohmann::json::object_t> jsonRequest = + readJsonPatchHelper(req, res); if (!jsonRequest) { return false; } - nlohmann::json::object_t* object = - jsonRequest->get_ptr<nlohmann::json::object_t*>(); - if (object == nullptr) + if (jsonRequest->empty()) { - BMCWEB_LOG_DEBUG("Json value is empty"); messages::emptyJSON(res); return false; } - return readJsonObject(*object, res, key, + return readJsonObject(*jsonRequest, res, key, std::forward<UnpackTypes&&>(in)...); } |