forked from bblanchon/ArduinoJson
Fixed assignment of JsonDocument
to JsonVariant
(issue #1023)
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
HEAD
|
||||
----
|
||||
|
||||
* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023)
|
||||
|
||||
v6.11.1 (2019-06-21)
|
||||
-------
|
||||
|
||||
|
@ -278,6 +278,10 @@ class JsonDocument : public Visitable {
|
||||
_data.remove(adaptString(key));
|
||||
}
|
||||
|
||||
FORCE_INLINE operator VariantConstRef() const {
|
||||
return VariantConstRef(&_data);
|
||||
}
|
||||
|
||||
protected:
|
||||
JsonDocument(MemoryPool pool) : _pool(pool) {
|
||||
_data.setNull();
|
||||
|
@ -222,6 +222,7 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
// set(ArrayConstRef)
|
||||
// set(ObjectRef)
|
||||
// set(ObjecConstRef)
|
||||
// set(const JsonDocument&)
|
||||
template <typename TVariant>
|
||||
typename enable_if<IsVisitable<TVariant>::value, bool>::type set(
|
||||
const TVariant &value) const;
|
||||
|
@ -108,3 +108,19 @@ TEST_CASE("JsonVariant with not enough memory") {
|
||||
REQUIRE(v.isNull());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::set(DynamicJsonDocument)") {
|
||||
DynamicJsonDocument doc1(1024);
|
||||
doc1["hello"] = "world";
|
||||
|
||||
DynamicJsonDocument doc2(1024);
|
||||
JsonVariant v = doc2.to<JsonVariant>();
|
||||
|
||||
// Should copy the doc
|
||||
v.set(doc1);
|
||||
doc1.clear();
|
||||
|
||||
std::string json;
|
||||
serializeJson(doc2, json);
|
||||
REQUIRE(json == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user