Remove nlohmann::json::object helpers
readJsonHelper existed back before the distinction between
nlohmann::json and nlohmann::json::object_t was understood. This commit
cleans up our sub-value parsing by removing readJsonHelper that accepts
a nlohmann::json overload, and always accepting via an object_t
overload. Functionally, these two are identical, given that
readJsonHelper only did a type check that was redundant.
Tested: Unit tests pass. Good coverage of these methods.
Change-Id: I734d956dd4bc2ddb14f6e3c735e15adf1f7e00a0
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index dbefefd..17d8990 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -491,9 +491,6 @@
bool complete = false;
};
-inline bool readJsonHelper(nlohmann::json& jsonRequest, crow::Response& res,
- std::span<PerUnpack> toUnpack);
-
inline bool readJsonHelperObject(nlohmann::json::object_t& obj,
crow::Response& res,
std::span<PerUnpack> toUnpack)
@@ -524,9 +521,9 @@
{
// Include the slash in the key so we can compare later
key = unpackSpec.key.substr(0, keysplitIndex + 1);
- nlohmann::json j;
- result = details::unpackValue<nlohmann::json>(item.second, key,
- res, j) &&
+ nlohmann::json::object_t j;
+ result = details::unpackValue<nlohmann::json::object_t>(
+ item.second, key, res, j) &&
result;
if (!result)
{
@@ -545,7 +542,7 @@
p.complete = true;
}
- result = readJsonHelper(j, res, nextLevel) && result;
+ result = readJsonHelperObject(j, res, nextLevel) && result;
break;
}
@@ -593,20 +590,6 @@
return result;
}
-inline bool readJsonHelper(nlohmann::json& jsonRequest, crow::Response& res,
- std::span<PerUnpack> toUnpack)
-{
- nlohmann::json::object_t* obj =
- jsonRequest.get_ptr<nlohmann::json::object_t*>();
- if (obj == nullptr)
- {
- BMCWEB_LOG_DEBUG("Json value is not an object");
- messages::unrecognizedRequestBody(res);
- return false;
- }
- return readJsonHelperObject(*obj, res, toUnpack);
-}
-
inline void packVariant(std::span<PerUnpack> /*toPack*/) {}
template <typename FirstType, typename... UnpackTypes>