From 8385d5fa3a91ca4ad2ef6cb10e8490d054a5657b Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 28 Sep 2020 21:11:38 +0200 Subject: [PATCH] Added wildcard key (`*`) for filters (closes #1309) --- CHANGELOG.md | 1 + extras/tests/JsonDeserializer/filter.cpp | 9 +++++++++ src/ArduinoJson/Deserialization/Filter.hpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e961915b..7facd64a 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/extras/tests/JsonDeserializer/filter.cpp b/extras/tests/JsonDeserializer/filter.cpp index 20b52c73..3e7867b9 100644 --- a/extras/tests/JsonDeserializer/filter.cpp +++ b/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]", diff --git a/src/ArduinoJson/Deserialization/Filter.hpp b/src/ArduinoJson/Deserialization/Filter.hpp index 25248879..63e06a56 100644 --- a/src/ArduinoJson/Deserialization/Filter.hpp +++ b/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: