mirror of
https://github.com/Telecominfraproject/wlan-cloud-analytics.git
synced 2026-01-27 10:22:33 +00:00
Framework fix for negative JSON fields.
This commit is contained in:
@@ -202,6 +202,34 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
Obj.set(Field,S);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const char * S) {
|
||||
Obj.set(Field,S);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int16_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int32_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int64_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint16_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint32_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint64_t Value) {
|
||||
Obj.set(Field,Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) {
|
||||
Poco::JSON::Array Array;
|
||||
for(const auto &i:S) {
|
||||
@@ -213,14 +241,6 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
Obj.set(Field,Array);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const char * S) {
|
||||
Obj.set(Field,S);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint64_t V) {
|
||||
Obj.set(Field,V);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringVec &V) {
|
||||
Poco::JSON::Array A;
|
||||
for(const auto &i:V)
|
||||
@@ -271,6 +291,27 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
Obj.set(Field, F(V));
|
||||
}
|
||||
|
||||
template<class T> void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector<T> &Value) {
|
||||
Poco::JSON::Array Arr;
|
||||
for(const auto &i:Value) {
|
||||
Poco::JSON::Object AO;
|
||||
i.to_json(AO);
|
||||
Arr.add(AO);
|
||||
}
|
||||
Obj.set(Field, Arr);
|
||||
}
|
||||
|
||||
template<class T> void field_to_json(Poco::JSON::Object &Obj, const char *Field, const T &Value) {
|
||||
Poco::JSON::Object Answer;
|
||||
Value.to_json(Answer);
|
||||
Obj.set(Field, Answer);
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
///////////////////////////
|
||||
///////////////////////////
|
||||
///////////////////////////
|
||||
|
||||
template<typename T> bool field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, T & V,
|
||||
std::function<T(const std::string &)> F) {
|
||||
if(Obj->has(Field))
|
||||
@@ -298,6 +339,35 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
V = (Obj->get(Field).toString() == "true");
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int16_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int16_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int32_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int32_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int64_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int64_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint16_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint16_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint32_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint32_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint64_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint64_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, Types::StringPairVec &Vec) {
|
||||
if(Obj->isArray(Field)) {
|
||||
@@ -335,34 +405,6 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector<T> &Value) {
|
||||
Poco::JSON::Array Arr;
|
||||
for(const auto &i:Value) {
|
||||
Poco::JSON::Object AO;
|
||||
i.to_json(AO);
|
||||
Arr.add(AO);
|
||||
}
|
||||
Obj.set(Field, Arr);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, int64_t Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, uint Value) {
|
||||
Obj.set(Field, Value);
|
||||
}
|
||||
|
||||
template<class T> void field_to_json(Poco::JSON::Object &Obj, const char *Field, const T &Value) {
|
||||
Poco::JSON::Object Answer;
|
||||
Value.to_json(Answer);
|
||||
Obj.set(Field, Answer);
|
||||
}
|
||||
|
||||
template<class T> void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, std::vector<T> &Value) {
|
||||
if(Obj->isArray(Field)) {
|
||||
Poco::JSON::Array::Ptr Arr = Obj->getArray(Field);
|
||||
@@ -375,36 +417,6 @@ namespace OpenWifi::RESTAPI_utils {
|
||||
}
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int16_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int16_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int32_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int32_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, int64_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<int64_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint16_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint16_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint32_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint32_t>();
|
||||
}
|
||||
|
||||
inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint64_t &Value) {
|
||||
if(Obj->has(Field))
|
||||
Value = Obj->get(Field).extract<uint64_t>();
|
||||
}
|
||||
|
||||
template<class T> void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, T &Value) {
|
||||
if(Obj->isObject(Field)) {
|
||||
Poco::JSON::Object::Ptr A = Obj->getObject(Field);
|
||||
|
||||
Reference in New Issue
Block a user