From 2ad969bcabe4ebd8198a1c3f0d9dd4eceb5a49ba Mon Sep 17 00:00:00 2001 From: Yurii Date: Sat, 5 Dec 2026 09:30:34 +0300 Subject: [PATCH] refactor: pass JSON response roots directly to toJson --- src/portal.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/portal.cpp b/src/portal.cpp index 9348d55..e69e34d 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -742,8 +742,7 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& doc = response->getRoot(); - toJson(*sensorId, *sensor, doc); + toJson(*sensorId, *sensor, response->getRoot()); // Send response response->setLength(); @@ -823,9 +822,8 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& responseDoc = response->getRoot(); if (const auto sensor = Sensors::getSettings(*sensorId)) { - toJson(*sensorId, *sensor, responseDoc); + toJson(*sensorId, *sensor, response->getRoot()); } // Send response @@ -858,8 +856,7 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& doc = response->getRoot(); - toJson(sensor->settings, sensor->result, doc); + toJson(sensor->settings, sensor->result, response->getRoot()); // Send response response->setLength(); @@ -912,8 +909,7 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& responseDoc = response->getRoot(); - toJson(sensor->settings, sensor->result, responseDoc); + toJson(sensor->settings, sensor->result, response->getRoot()); // Send response response->setLength(); @@ -988,8 +984,7 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& responseDoc = response->getRoot(); - toJson(sensor->settings, sensor->result, responseDoc); + toJson(sensor->settings, sensor->result, response->getRoot()); // Send response response->setLength(); @@ -1002,8 +997,7 @@ static void restApi() { webServer->on("/api/vars", HTTP_GET, [](AsyncWebServerRequest *request) { // Prepare response auto *response = new AsyncJsonResponse(); - auto& doc = response->getRoot(); - toJson(vars, doc); + toJson(vars, response->getRoot()); // Send response response->setLength(); @@ -1025,8 +1019,7 @@ static void restApi() { // Prepare response auto *response = new AsyncJsonResponse(); - auto& responseDoc = response->getRoot(); - toJson(vars, responseDoc); + toJson(vars, response->getRoot()); // Send response response->setLength();