Skip to content

Commit

Permalink
fix: Refactor handleJson function parameters to pass JsonVariant by r…
Browse files Browse the repository at this point in the history
…eference
  • Loading branch information
ZanzyTHEbar committed Apr 6, 2024
1 parent 5932f2f commit e4c9671
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion NetworkManager/examples/customHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void setupServer() {
// made to /api/customJson
async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
"/api/customJson",
[&](AsyncWebServerRequest* request, JsonVariant json) {
[&](AsyncWebServerRequest* request, JsonVariant& json) {
JsonDocument doc;
doc["hello"] = "world";
doc["number"] = 42;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void setupServer() {

async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
"/api/customJson",
[&](AsyncWebServerRequest* request, JsonVariant json) {
[&](AsyncWebServerRequest* request, JsonVariant& json) {
JsonDocument doc;
doc["hello"] = "world";
doc["number"] = 42;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/include/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BaseAPI : public API_Utilities {
void save(AsyncWebServerRequest* request);
void rssi(AsyncWebServerRequest* request);

void handleJson(AsyncWebServerRequest* request, JsonVariant jsonData);
void handleJson(AsyncWebServerRequest* request, JsonVariant& jsonData);

using route_method = void (BaseAPI::*)(AsyncWebServerRequest*);
using route_t = std::unordered_map<std::string, route_method>;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/src/api/base_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void BaseAPI::setWiFiTXPower(AsyncWebServerRequest* request) {
}
}

void BaseAPI::handleJson(AsyncWebServerRequest* request, JsonVariant jsonData) {
void BaseAPI::handleJson(AsyncWebServerRequest* request, JsonVariant& jsonData) {
switch (_networkMethodsMap_enum[request->method()]) {
case POST: {
auto jsonObj = jsonData.as<JsonObject>();
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager/src/api/rest_api_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void APIServer::begin() {

async_server.server.addHandler(new AsyncCallbackJsonWebHandler(
json_url.c_str(),
[&](AsyncWebServerRequest* request, JsonVariant json) {
[&](AsyncWebServerRequest* request, JsonVariant& json) {
handleJson(request, json);
}));

Expand Down

0 comments on commit e4c9671

Please sign in to comment.