|
11 | 11 | #include <ArduinoJson/Object/MemberProxy.hpp> |
12 | 12 | #include <ArduinoJson/Polyfills/utility.hpp> |
13 | 13 | #include <ArduinoJson/Variant/JsonVariantConst.hpp> |
14 | | -#include <ArduinoJson/Variant/VariantTo.hpp> |
15 | 14 |
|
16 | 15 | ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE |
17 | 16 |
|
@@ -152,12 +151,33 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> { |
152 | 151 | return to<JsonVariant>().set(src); |
153 | 152 | } |
154 | 153 |
|
155 | | - // Clears the document and converts it to the specified type. |
| 154 | + // Sets the document to an empty array. |
156 | 155 | // https://arduinojson.org/v7/api/jsondocument/to/ |
157 | | - template <typename T> |
158 | | - typename detail::VariantTo<T>::type to() { |
| 156 | + template <typename T, |
| 157 | + detail::enable_if_t<detail::is_same<T, JsonArray>::value, int> = 0> |
| 158 | + JsonArray to() { |
| 159 | + clear(); |
| 160 | + data_.toArray(); |
| 161 | + return JsonArray(&data_, &resources_); |
| 162 | + } |
| 163 | + |
| 164 | + // Sets the document to an empty object. |
| 165 | + // https://arduinojson.org/v7/api/jsondocument/to/ |
| 166 | + template <typename T, |
| 167 | + detail::enable_if_t<detail::is_same<T, JsonObject>::value, int> = 0> |
| 168 | + JsonObject to() { |
159 | 169 | clear(); |
160 | | - return getVariant().template to<T>(); |
| 170 | + data_.toObject(); |
| 171 | + return JsonObject(&data_, &resources_); |
| 172 | + } |
| 173 | + |
| 174 | + // Sets the document to null. |
| 175 | + // https://arduinojson.org/v7/api/jsondocument/to/ |
| 176 | + template <typename T, detail::enable_if_t< |
| 177 | + detail::is_same<T, JsonVariant>::value, int> = 0> |
| 178 | + JsonVariant to() { |
| 179 | + clear(); |
| 180 | + return JsonVariant(&data_, &resources_); |
161 | 181 | } |
162 | 182 |
|
163 | 183 | // DEPRECATED: use obj["key"].is<T>() instead |
|
0 commit comments