diff options
| author | James Feist <james.feist@linux.intel.com> | 2018-12-13 14:47:43 -0800 |
|---|---|---|
| committer | James Feist <james.feist@linux.intel.com> | 2018-12-19 19:49:22 +0000 |
| commit | 318226c278a18c1492b2235cb2c3b2ce5ed09900 (patch) | |
| tree | bac9ceb32fff3f2f1fe0c9882e8d50e5fec1848f /redfish-core/include/utils | |
| parent | 6b5e77d6a2733b78bcbacb9f845f5763d1023e6d (diff) | |
| download | bmcweb-318226c278a18c1492b2235cb2c3b2ce5ed09900.tar.gz bmcweb-318226c278a18c1492b2235cb2c3b2ce5ed09900.zip | |
json_utils: readJson add array support
Add std::array support to readJson.
Change-Id: I32bb28908f195fd3443556c40b71eaabd105db25
Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'redfish-core/include/utils')
| -rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp index 38f43fa..2eeace1 100644 --- a/redfish-core/include/utils/json_utils.hpp +++ b/redfish-core/include/utils/json_utils.hpp @@ -66,6 +66,18 @@ template <typename Type> struct is_vector<std::vector<Type>> : std::true_type template <typename Type> constexpr bool is_vector_v = is_vector<Type>::value; +template <typename Type> struct is_std_array : std::false_type +{ +}; + +template <typename Type, std::size_t size> +struct is_std_array<std::array<Type, size>> : std::true_type +{ +}; + +template <typename Type> +constexpr bool is_std_array_v = is_std_array<Type>::value; + template <typename Type> void unpackValue(nlohmann::json& jsonValue, const std::string& key, crow::Response& res, Type& value) @@ -117,6 +129,25 @@ void unpackValue(nlohmann::json& jsonValue, const std::string& key, value = std::move(jsonValue); } + else if constexpr (is_std_array_v<Type>) + { + if (!jsonValue.is_array()) + { + messages::propertyValueTypeError(res, res.jsonValue.dump(), key); + return; + } + if (jsonValue.size() != value.size()) + { + messages::propertyValueTypeError(res, res.jsonValue.dump(), key); + return; + } + size_t index = 0; + for (const auto& val : jsonValue.items()) + { + unpackValue<typename Type::value_type>(val.value(), key, res, + value[index++]); + } + } else if constexpr (is_vector_v<Type>) { if (!jsonValue.is_array()) |

