diff --git a/CHANGELOG.md b/CHANGELOG.md index 796e21bc..e4e01bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fix "no matching function" with `JsonObjectConst::operator[]` (issue #2019) + v7.0.0 (2024-01-03) ------ diff --git a/extras/tests/JsonObject/subscript.cpp b/extras/tests/JsonObject/subscript.cpp index 1e58476c..adc05e89 100644 --- a/extras/tests/JsonObject/subscript.cpp +++ b/extras/tests/JsonObject/subscript.cpp @@ -252,3 +252,11 @@ TEST_CASE("JsonObject::operator[]") { REQUIRE(false == obj["hello"]["world"].is()); } } + +TEST_CASE("JsonObjectConst::operator[]") { + JsonDocument doc; + doc["hello"] = "world"; + JsonObjectConst obj = doc.as(); + + REQUIRE(obj["hello"] == "world"); // issue #2019 +} diff --git a/src/ArduinoJson/Object/JsonObjectConst.hpp b/src/ArduinoJson/Object/JsonObjectConst.hpp index 641db6cf..16f30437 100644 --- a/src/ArduinoJson/Object/JsonObjectConst.hpp +++ b/src/ArduinoJson/Object/JsonObjectConst.hpp @@ -101,8 +101,9 @@ class JsonObjectConst : public detail::VariantOperators { FORCE_INLINE typename detail::enable_if::value, JsonVariantConst>::type operator[](TChar* key) const { - return JsonVariantConst( - detail::ObjectData::getMember(data_, detail::adaptString(key))); + return JsonVariantConst(detail::ObjectData::getMember( + data_, detail::adaptString(key), resources_), + resources_); } // DEPRECATED: always returns zero