From 7b5b4e0d655f3c14c34a48bb8c8bb612dac18a95 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Thu, 17 Oct 2024 16:21:31 +0200 Subject: [PATCH] UI Thermo add checks for from and to json --- src/UI/UI_thermo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/UI/UI_thermo.cpp b/src/UI/UI_thermo.cpp index 784fc3e..cc2bdbf 100644 --- a/src/UI/UI_thermo.cpp +++ b/src/UI/UI_thermo.cpp @@ -102,6 +102,8 @@ void UI_thermo::from_json(const json &j) this->m_value = j.at("value"); this->m_unit = j.at("unit"); this->m_color_map.clear(); + if (!j.contains("color_map")) + return; for (auto &i : j["color_map"]) { double k = i.at("key"); @@ -117,6 +119,8 @@ json UI_thermo::to_json(size_t id) const j["max"] = this->m_max; j["value"] = this->m_value; j["unit"] = this->m_unit; + if (this->m_color_map.empty()) + return j; j["color_map"] = json::array(); for (auto &[key, value] : this->m_color_map) {