mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Support JsonDocument*
This commit is contained in:
@@ -43,4 +43,24 @@ TEST_CASE("JsonVariant::add()") {
|
|||||||
|
|
||||||
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
REQUIRE(var.as<std::string>() == "{\"val\":123}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("add JsonDocument to new variant") {
|
||||||
|
StaticJsonDocument<128> doc2;
|
||||||
|
doc2["hello"] = "world";
|
||||||
|
|
||||||
|
var.add(doc2);
|
||||||
|
|
||||||
|
CHECK(var.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||||
|
CHECK(var.memoryUsage() == JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("add JsonDocument* to new variant") {
|
||||||
|
StaticJsonDocument<128> doc2;
|
||||||
|
doc2["hello"] = "world";
|
||||||
|
|
||||||
|
var.add(&doc2);
|
||||||
|
|
||||||
|
CHECK(var.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||||
|
CHECK(var.memoryUsage() == JSON_ARRAY_SIZE(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,4 +303,9 @@ inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
inline void convertToJson(JsonDocument* src, VariantRef dst) {
|
||||||
|
VariantData* data = getData(dst);
|
||||||
|
data->setPointer(getData(src->as<VariantRef>()));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ARDUINOJSON_NAMESPACE
|
} // namespace ARDUINOJSON_NAMESPACE
|
||||||
|
|||||||
Reference in New Issue
Block a user