mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Support ElementProxy
and MemberProxy
in JsonDocument
's constructor
This commit is contained in:
@ -1,12 +1,16 @@
|
|||||||
ArduinoJson: change log
|
ArduinoJson: change log
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
HEAD
|
||||||
|
----
|
||||||
|
|
||||||
* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name
|
* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name
|
||||||
* Add MsgPack bin8/bin16/bin32 support (PR #2078 by @Sanae6)
|
* Add MsgPack bin8/bin16/bin32 support (PR #2078 by @Sanae6)
|
||||||
* Make string support even more generic (PR #2084 by @d-a-v)
|
* Make string support even more generic (PR #2084 by @d-a-v)
|
||||||
* Optimize `deserializeMsgPack()`
|
* Optimize `deserializeMsgPack()`
|
||||||
* Allow using a `JsonVariant` as a key or index (issue #2080)
|
* Allow using a `JsonVariant` as a key or index (issue #2080)
|
||||||
Note: works only for reading, not for writing
|
Note: works only for reading, not for writing
|
||||||
|
* Support `ElementProxy` and `MemberProxy` in `JsonDocument`'s constructor
|
||||||
|
|
||||||
v7.0.4 (2024-03-12)
|
v7.0.4 (2024-03-12)
|
||||||
------
|
------
|
||||||
|
@ -126,4 +126,22 @@ TEST_CASE("JsonDocument constructor") {
|
|||||||
|
|
||||||
REQUIRE(doc2.as<std::string>() == "hello");
|
REQUIRE(doc2.as<std::string>() == "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("JsonDocument(ElementProxy)") {
|
||||||
|
JsonDocument doc1;
|
||||||
|
deserializeJson(doc1, "[\"hello\",\"world\"]");
|
||||||
|
|
||||||
|
JsonDocument doc2(doc1[1]);
|
||||||
|
|
||||||
|
REQUIRE(doc2.as<std::string>() == "world");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("JsonDocument(MemberProxy)") {
|
||||||
|
JsonDocument doc1;
|
||||||
|
deserializeJson(doc1, "{\"hello\":\"world\"}");
|
||||||
|
|
||||||
|
JsonDocument doc2(doc1["hello"]);
|
||||||
|
|
||||||
|
REQUIRE(doc2.as<std::string>() == "world");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,13 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
|
|
||||||
// Construct from variant, array, or object
|
// Construct from variant, array, or object
|
||||||
template <typename T>
|
template <typename T>
|
||||||
JsonDocument(const T& src,
|
JsonDocument(
|
||||||
Allocator* alloc = detail::DefaultAllocator::instance(),
|
const T& src, Allocator* alloc = detail::DefaultAllocator::instance(),
|
||||||
typename detail::enable_if<
|
typename detail::enable_if<
|
||||||
detail::is_same<T, JsonVariant>::value ||
|
detail::IsVariant<T>::value || detail::is_same<T, JsonArray>::value ||
|
||||||
detail::is_same<T, JsonVariantConst>::value ||
|
detail::is_same<T, JsonArrayConst>::value ||
|
||||||
detail::is_same<T, JsonArray>::value ||
|
detail::is_same<T, JsonObject>::value ||
|
||||||
detail::is_same<T, JsonArrayConst>::value ||
|
detail::is_same<T, JsonObjectConst>::value>::type* = 0)
|
||||||
detail::is_same<T, JsonObject>::value ||
|
|
||||||
detail::is_same<T, JsonObjectConst>::value>::type* = 0)
|
|
||||||
: JsonDocument(alloc) {
|
: JsonDocument(alloc) {
|
||||||
set(src);
|
set(src);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user