sandeepindia | e64778d | 2022-12-06 00:17:19 +0530 | [diff] [blame^] | 1 | /* |
| 2 | # ================================================================================== |
| 3 | # Copyright (c) 2020 HCL Technologies Limited. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ================================================================================== |
| 17 | */ |
| 18 | #include"XAppConfig.h" |
| 19 | namespace xapp { |
| 20 | namespace model { |
| 21 | void from_json(const nlohmann::json& j, XAppConfig& ref) { |
| 22 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
| 23 | ref.validate_json(j); |
| 24 | j.at("metadata").get_to(ref.m_ConfigMetadata); |
| 25 | j.at("config").get_to(ref.config); |
| 26 | |
| 27 | } |
| 28 | void from_json(const nlohmann::json& j, std::vector<XAppConfig>& ref) { |
| 29 | for (auto& element : j) { |
| 30 | XAppConfig tmp; |
| 31 | tmp.validate_json(element); |
| 32 | for (auto& val : element.items()) |
| 33 | { |
| 34 | if (val.key() == "metadata") { |
| 35 | tmp.m_ConfigMetadata.ConfigType = val.value()["configType"]; |
| 36 | tmp.m_ConfigMetadata.XappName = val.value()["xappName"]; |
| 37 | } |
| 38 | else if (val.key() == "config") { |
| 39 | tmp.config = val.value(); |
| 40 | } |
| 41 | } |
| 42 | ref.push_back(tmp); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void to_json(nlohmann::json& j, const XAppConfig& ref) { |
| 47 | j = nlohmann::json{ |
| 48 | {"metadata",{{"configType",ref.m_ConfigMetadata.ConfigType},{"xappName",ref.m_ConfigMetadata.XappName}}}, |
| 49 | {"config",ref.config} |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | void to_json(nlohmann::json& j, const std::vector<XAppConfig>& ref) { |
| 54 | for (int i = 0; i < ref.size(); i++) |
| 55 | { |
| 56 | nlohmann::json tmp_j; |
| 57 | to_json(tmp_j, ref[i]); |
| 58 | j += tmp_j; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |