From 9712f8ac42746e65f32c2bc3de0835846652568e Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Fri, 21 Sep 2018 13:38:49 -0700 Subject: Implement a new way of unpacking json to structs The existing way of decoding json structures, while fast has some disadvantages. 1. it's very verbose to write. 2. It requires in depth knowlege of redfish error messages to get correct. 3. It _can_ lead to undesired behavior, like half of a patch being applied, if only some of the values have bad types. This commit implements a new interface for decoding redfish json named.... readJson. It is a templated function, that lets you decode json values based on type easily, while still handling all the correct error codes that were handled previously. Use is done similar to the example below: std::string required; boost::optional optional; if (!json_util::readJson(req, res, "OptionalParam", optional, "RequiredParam", required)) { return; } if (optional){ // optional param was given, take action. } As part of this patchset, the systems schema is moved to the new interface, which deletes some of the code involved and shows the improvement in clarity. Change-Id: I041a97c84d294df8cd4de4c2702e5ee22c0bc120 Signed-off-by: Ed Tanous --- redfish-core/src/utils/json_utils.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'redfish-core/src/utils') diff --git a/redfish-core/src/utils/json_utils.cpp b/redfish-core/src/utils/json_utils.cpp index 868601f72d..e14131713a 100644 --- a/redfish-core/src/utils/json_utils.cpp +++ b/redfish-core/src/utils/json_utils.cpp @@ -15,8 +15,6 @@ */ #include "utils/json_utils.hpp" -#include - namespace redfish { @@ -521,5 +519,4 @@ bool processJsonFromRequest(crow::Response& res, const crow::Request& req, } } // namespace json_util - } // namespace redfish -- cgit v1.2.3