Ver código fonte

Added wildcard key (`*`) for filters (closes #1309)

Benoit Blanchon 5 anos atrás
pai
commit
8385d5fa3a

+ 1 - 0
CHANGELOG.md

@@ -24,6 +24,7 @@ v6.16.0 (2020-08-01)
 * Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s
 * Added string deduplication (issue #1303)
 * Added `JsonString::operator!=`
+* Added wildcard key (`*`) for filters (issue #1309)
 * Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default
 * Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy`
 * Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311)

+ 9 - 0
extras/tests/JsonDeserializer/filter.cpp

@@ -214,6 +214,15 @@ TEST_CASE("Filtering") {
       "{\"example\":{\"outcome\":42}}",
       2 * JSON_OBJECT_SIZE(1) + 16
     },
+    {
+      // wildcard
+      "{\"example\":{\"type\":\"int\",\"outcome\":42}}",
+      "{\"*\":{\"outcome\":true}}",
+      10,
+      DeserializationError::Ok,
+      "{\"example\":{\"outcome\":42}}",
+      2 * JSON_OBJECT_SIZE(1) + 16
+    },
     {
       // only the first element of array counts
       "[1,2,3]",

+ 1 - 1
src/ArduinoJson/Deserialization/Filter.hpp

@@ -33,7 +33,7 @@ class Filter {
     if (_variant == true)  // "true" means "allow recursively"
       return *this;
     else
-      return Filter(_variant[key]);
+      return Filter(_variant[key] | _variant["*"]);
   }
 
  private: