2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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 # ==================================================================================
18 #include"SubscriptionData.h"
21 void from_json(const nlohmann::json& j, SubscriptionData& ref) {
23 std::cout << __PRETTY_FUNCTION__ << std::endl;
25 if (j.contains("SubscriptionId")) {
26 j.at("SubscriptionId").get_to(ref.SubscriptionID);
28 if (j.contains("SubscriptionInstances")) {
29 j.at("SubscriptionInstances").get_to(ref.m_SubscriptionInstances);
32 if (j.contains("Meid")) {
33 j.at("Meid").get_to(ref.Meid);
36 if (j.contains("ClientEndpoint")) {
37 j.at("ClientEndpoint").get_to(ref.ClientEndpoint);
42 void from_json(const nlohmann::json& j, std::vector<SubscriptionData>& ref) {
43 for (auto& element : j) {
45 tmp.validate_json(element);
46 for (auto& val : element.items())
48 if (val.key() == "SubscriptionId") {
49 tmp.SubscriptionID = val.value();
51 else if (val.key() == "Meid") {
52 tmp.Meid = val.value();
54 else if (val.key() == "ClientEndpoint") {
56 tmp.ClientEndpoint.assign(val.value().begin(), val.value().end());
58 else if (val.key() == "SubscriptionInstances") {
59 from_json(val.value(), tmp.m_SubscriptionInstances);
61 tmp.m_SubscriptionInstances.E2EventInstanceId= val.value()["E2EventInstanceId"];
62 tmp.m_SubscriptionInstances.XappEventInstanceId= val.value()["XappEventInstanceId"];
63 if (val.value().contains("ErrorCause"))
65 tmp.m_SubscriptionInstances.ErrorCause= val.value()["ErrorCause"];
67 if (val.value().contains("ErrorSource"))
69 tmp.m_SubscriptionInstances.ErrorCause = val.value()["ErrorSource"];
71 if (val.value().contains("TimeoutType"))
73 tmp.m_SubscriptionInstances.ErrorCause = val.value()["TimeoutType"];
84 void to_json(nlohmann::json& j, const SubscriptionData& ref) {
87 {"SubscriptionId",ref.SubscriptionID},
89 {"ClientEndpoint", ref.ClientEndpoint}//,
90 //{"SubscriptionInstances", {{"XappEventInstanceId", ref.m_SubscriptionInstances.XappEventInstanceId},{"E2EventInstanceId", ref.m_SubscriptionInstances.E2EventInstanceId},{"ErrorCause", ref.m_SubscriptionInstances.ErrorCause},{"ErrorSource", ref.m_SubscriptionInstances.ErrorSource},{"TimeoutType", ref.m_SubscriptionInstances.TimeoutType}}}
94 to_json(tmp_j, ref.m_SubscriptionInstances);
95 j["SubscriptionInstances"] = tmp_j;
97 if (ref.SubscriptionID != "") {
98 j["SubscriptionId"] = ref.SubscriptionID;
100 if (ref.Meid.length() > 0) {
101 j["Meid"] = ref.Meid;
103 if (ref.ClientEndpoint.size() > 0) {
104 j["ClientEndpoint"] = ref.ClientEndpoint;
106 if (ref.m_SubscriptionInstances.size() > 0) {
107 nlohmann::json tmp_j;
108 to_json(tmp_j, ref.m_SubscriptionInstances);
109 j["SubscriptionInstances"] = tmp_j;
112 void to_json(nlohmann::json& j, const std::vector<SubscriptionData>& ref) {
113 for (int i = 0; i < ref.size(); i++)
115 nlohmann::json tmp_j;
116 to_json(tmp_j, ref[i]);