From 8a3b3cfeec33e9e3a670f92ab24cee49dd92bd6e Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 15 Mar 2022 11:36:08 +0100 Subject: [PATCH] Element proxy --- extras/tests/JsonDocument/ElementProxy.cpp | 8 ++++++++ src/ArduinoJson/Array/ElementProxy.hpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/extras/tests/JsonDocument/ElementProxy.cpp b/extras/tests/JsonDocument/ElementProxy.cpp index 1912d5f9..8e13180e 100644 --- a/extras/tests/JsonDocument/ElementProxy.cpp +++ b/extras/tests/JsonDocument/ElementProxy.cpp @@ -204,3 +204,11 @@ TEST_CASE("ElementProxy::operator[]") { REQUIRE(doc.as() == "[null,[null,null,42]]"); } } + +TEST_CASE("ElementProxy::link()") { + StaticJsonDocument<1024> doc1, doc2; + doc1[0].link(doc2); + doc2["hello"] = "world"; + + CHECK(doc1.as() == "[{\"hello\":\"world\"}]"); +} diff --git a/src/ArduinoJson/Array/ElementProxy.hpp b/src/ArduinoJson/Array/ElementProxy.hpp index d54de494..77f241a7 100644 --- a/src/ArduinoJson/Array/ElementProxy.hpp +++ b/src/ArduinoJson/Array/ElementProxy.hpp @@ -92,6 +92,10 @@ class ElementProxy : public VariantOperators >, return getOrAddUpstreamElement().template to(); } + FORCE_INLINE void link(VariantConstRef value) const { + getOrAddUpstreamElement().link(value); + } + // Replaces the value // // bool set(const TValue&)