Copy JsonArray and JsonObject, instead of storing pointers (fixes #780)

This commit is contained in:
Benoit Blanchon
2018-09-11 16:05:56 +02:00
parent 2998a55f0b
commit b106b1ed14
52 changed files with 971 additions and 978 deletions

View File

@ -23,9 +23,7 @@ TEST_CASE("JsonVariant::operator[]") {
}
SECTION("The JsonVariant is a JsonArray") {
DynamicJsonDocument doc2;
JsonArray array = doc2.to<JsonArray>();
var.set(array);
JsonArray array = var.to<JsonArray>();
SECTION("get value") {
array.add("element at index 0");
@ -62,9 +60,7 @@ TEST_CASE("JsonVariant::operator[]") {
}
SECTION("The JsonVariant is a JsonObject") {
DynamicJsonDocument doc2;
JsonObject object = doc2.to<JsonObject>();
var.set(object);
JsonObject object = var.to<JsonObject>();
SECTION("get value") {
object["a"] = "element at key \"a\"";
@ -92,6 +88,11 @@ TEST_CASE("JsonVariant::operator[]") {
REQUIRE(1 == var.size());
REQUIRE(std::string("world") == var["hello"]);
}
SECTION("var[key].to<JsonArray>()") {
JsonArray arr = var["hello"].to<JsonArray>();
REQUIRE(arr.isNull() == false);
}
}
#if defined(HAS_VARIABLE_LENGTH_ARRAY) && \