From 43559b5e373ad0d9ec4043a26df347ce74cdc727 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Thu, 24 Mar 2022 11:47:42 -0700 Subject: [PATCH] Framework fix for negative JSON fields. --- src/framework/MicroService.h | 144 +++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 5e8e0fc..401468f 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -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 void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector &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 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 bool field_from_json(Poco::JSON::Object::Ptr Obj, const char *Field, T & V, std::function 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(); + } + + 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(); + } + + 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(); + } + + 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(); + } + + 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(); + } + + 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(); + } 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 void field_to_json(Poco::JSON::Object &Obj, const char *Field, const std::vector &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 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 void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, std::vector &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(); - } - - 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(); - } - - 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(); - } - - 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(); - } - - 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(); - } - - 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(); - } - template 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);