diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c506ab..2f47083a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ ArduinoJson: change log ======================= +v6.21.5 (2024-01-10) +------- + +* Fix warning `function returns incomplete class type` on IAR (issue #2001) +* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029) +* Remove unused files in the PlatformIO package + +v6.21.4 (2023-12-07) +------- + +* Fix error `'std::string' has not been declared` (issue #1967) +* Fix error `'std::string_view' has not been declared` (issue #1967) +* Fix error `no instance of overloaded function...` on recent IAR compilers (issue #2001) + v6.21.3 (2023-07-23) ------- diff --git a/CMakeLists.txt b/CMakeLists.txt index a79bc663..71b3d535 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ if(ESP_PLATFORM) return() endif() -project(ArduinoJson VERSION 6.21.3) +project(ArduinoJson VERSION 6.21.5) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) diff --git a/README.md b/README.md index 16d93a3a..96879e01 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ [![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) [![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.3&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.3) -[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.3)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.3) -[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.3&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson) +[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.5&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.5) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.5)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.5) +[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.5&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson) [![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github&color=orange)](https://github.com/bblanchon/ArduinoJson/stargazers) [![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github&color=orange)](https://github.com/sponsors/bblanchon) diff --git a/appveyor.yml b/appveyor.yml index 4a9789be..8a6a332b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 6.21.3.{build} +version: 6.21.5.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 diff --git a/extras/tests/Cpp17/string_view.cpp b/extras/tests/Cpp17/string_view.cpp index 6a51ce2d..7ef65626 100644 --- a/extras/tests/Cpp17/string_view.cpp +++ b/extras/tests/Cpp17/string_view.cpp @@ -1,8 +1,16 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STD_STRING 0 + #include #include -#include - #if !ARDUINOJSON_ENABLE_STRING_VIEW # error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1 #endif @@ -19,7 +27,7 @@ TEST_CASE("string_view") { SECTION("JsonDocument::set()") { doc.set(std::string_view("123", 2)); - REQUIRE(doc.as() == "12"); + REQUIRE(doc.as() == "12"); } SECTION("JsonDocument::operator[]() const") { diff --git a/extras/tests/JsonVariant/converters.cpp b/extras/tests/JsonVariant/converters.cpp index cd4e7c21..89afc9b7 100644 --- a/extras/tests/JsonVariant/converters.cpp +++ b/extras/tests/JsonVariant/converters.cpp @@ -158,6 +158,11 @@ void convertToJson(char c, JsonVariant var) { char buf[] = {c, 0}; var.set(buf); } + +void convertFromJson(JsonVariantConst src, char& dst) { + auto p = src.as(); + dst = p ? p[0] : 0; +} } // namespace ArduinoJson TEST_CASE("Convert char to string") { // issue #1922 @@ -165,3 +170,9 @@ TEST_CASE("Convert char to string") { // issue #1922 doc.set('a'); REQUIRE(doc.as() == "a"); } + +TEST_CASE("Convert string to char") { // issue #1963 + StaticJsonDocument<64> doc; + doc.set("a"); + REQUIRE(doc.as() == 'a'); +} diff --git a/extras/tests/JsonVariant/types.cpp b/extras/tests/JsonVariant/types.cpp index 42242991..91b4c1e2 100644 --- a/extras/tests/JsonVariant/types.cpp +++ b/extras/tests/JsonVariant/types.cpp @@ -140,6 +140,13 @@ TEST_CASE("volatile") { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); + SECTION("volatile bool") { // issue #2029 + volatile bool f = true; + variant.set(f); + CHECK(variant.is() == true); + CHECK(variant.as() == true); + } + SECTION("volatile int") { volatile int f = 42; variant.set(f); diff --git a/extras/tests/Misc/CMakeLists.txt b/extras/tests/Misc/CMakeLists.txt index 5655a089..3a1eb898 100644 --- a/extras/tests/Misc/CMakeLists.txt +++ b/extras/tests/Misc/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable(MiscTests arithmeticCompare.cpp conflicts.cpp FloatParts.cpp + issue1967.cpp JsonString.cpp NoArduinoHeader.cpp printable.cpp diff --git a/extras/tests/Misc/issue1967.cpp b/extras/tests/Misc/issue1967.cpp new file mode 100644 index 00000000..a8d6b948 --- /dev/null +++ b/extras/tests/Misc/issue1967.cpp @@ -0,0 +1,13 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include +#define ARDUINOJSON_ENABLE_STD_STRING 1 + +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STRING_VIEW 0 + +#include diff --git a/idf_component.yml b/idf_component.yml index 51be4722..afc8b8a8 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "6.21.3" +version: "6.21.5" description: >- A simple and efficient JSON library for embedded C++. ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. diff --git a/library.json b/library.json index 9b5d7df4..0303e99d 100644 --- a/library.json +++ b/library.json @@ -7,16 +7,14 @@ "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "6.21.3", + "version": "6.21.5", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" }, - "exclude": [ - ".devcontainer", - ".github", - "extras" - ], + "export": { + "include": ["src", "examples", "LICENSE.txt", "ArduinoJson.h"] + }, "frameworks": "*", "platforms": "*", "build": { diff --git a/library.properties b/library.properties index 6a285cf0..aa6de9a9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoJson -version=6.21.3 +version=6.21.5 author=Benoit Blanchon maintainer=Benoit Blanchon sentence=A simple and efficient JSON library for embedded C++. diff --git a/src/ArduinoJson/Strings/Adapters/RamString.hpp b/src/ArduinoJson/Strings/Adapters/RamString.hpp index 12c67c94..0fa2d5be 100644 --- a/src/ArduinoJson/Strings/Adapters/RamString.hpp +++ b/src/ArduinoJson/Strings/Adapters/RamString.hpp @@ -8,6 +8,7 @@ #include // strcmp #include +#include #include #include @@ -27,7 +28,7 @@ class ZeroTerminatedRamString { return !str_; } - size_t size() const { + FORCE_INLINE size_t size() const { return str_ ? ::strlen(str_) : 0; } diff --git a/src/ArduinoJson/Variant/ConverterImpl.hpp b/src/ArduinoJson/Variant/ConverterImpl.hpp index e95b33e5..0708f52f 100644 --- a/src/ArduinoJson/Variant/ConverterImpl.hpp +++ b/src/ArduinoJson/Variant/ConverterImpl.hpp @@ -8,6 +8,14 @@ #include #include +#if ARDUINOJSON_ENABLE_STD_STRING +# include +#endif + +#if ARDUINOJSON_ENABLE_STRING_VIEW +# include +#endif + ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE template diff --git a/src/ArduinoJson/Variant/VariantImpl.hpp b/src/ArduinoJson/Variant/VariantImpl.hpp index c122a2f4..abeed0dc 100644 --- a/src/ArduinoJson/Variant/VariantImpl.hpp +++ b/src/ArduinoJson/Variant/VariantImpl.hpp @@ -110,6 +110,13 @@ inline JsonVariant VariantRefBase::add() const { variantAddElement(getOrCreateData(), getPool())); } +template +template +inline typename enable_if::value, T>::type +VariantRefBase::as() const { + return Converter::fromJson(getVariant()); +} + template inline JsonVariant VariantRefBase::getVariant() const { return JsonVariant(getPool(), getData()); @@ -120,6 +127,30 @@ inline JsonVariant VariantRefBase::getOrCreateVariant() const { return JsonVariant(getPool(), getOrCreateData()); } +template +template +inline typename enable_if::value, bool>::type +VariantRefBase::is() const { + return Converter::checkJson(getVariant()); +} + +template +template +inline bool VariantRefBase::set(const T& value) const { + Converter::type>::toJson(value, + getOrCreateVariant()); + MemoryPool* pool = getPool(); + return pool && !pool->overflowed(); +} + +template +template +inline bool VariantRefBase::set(T* value) const { + Converter::toJson(value, getOrCreateVariant()); + MemoryPool* pool = getPool(); + return pool && !pool->overflowed(); +} + template template inline typename enable_if::value, JsonArray>::type diff --git a/src/ArduinoJson/Variant/VariantRefBase.hpp b/src/ArduinoJson/Variant/VariantRefBase.hpp index 2afdda6a..3f29608a 100644 --- a/src/ArduinoJson/Variant/VariantRefBase.hpp +++ b/src/ArduinoJson/Variant/VariantRefBase.hpp @@ -57,11 +57,10 @@ class VariantRefBase : public VariantTag { // https://arduinojson.org/v6/api/jsonvariant/as/ template FORCE_INLINE typename enable_if::value, T>::type - as() const { - return Converter::fromJson(getVariant()); - } + as() const; - template + template ::value>::type> FORCE_INLINE operator T() const { return as(); } @@ -91,9 +90,7 @@ class VariantRefBase : public VariantTag { template FORCE_INLINE typename enable_if::value, bool>::type - is() const { - return Converter::checkJson(getVariant()); - } + is() const; // Returns true if the value is of the specified type. // https://arduinojson.org/v6/api/jsonvariant/is/ @@ -122,20 +119,12 @@ class VariantRefBase : public VariantTag { // Copies the specified value. // https://arduinojson.org/v6/api/jsonvariant/set/ template - FORCE_INLINE bool set(const T& value) const { - Converter::toJson(value, getOrCreateVariant()); - MemoryPool* pool = getPool(); - return pool && !pool->overflowed(); - } + FORCE_INLINE bool set(const T& value) const; // Copies the specified value. // https://arduinojson.org/v6/api/jsonvariant/set/ template - FORCE_INLINE bool set(T* value) const { - Converter::toJson(value, getOrCreateVariant()); - MemoryPool* pool = getPool(); - return pool && !pool->overflowed(); - } + FORCE_INLINE bool set(T* value) const; // Returns the size of the array or object. // https://arduinojson.org/v6/api/jsonvariant/size/ diff --git a/src/ArduinoJson/version.hpp b/src/ArduinoJson/version.hpp index 5e6500a4..160980e9 100644 --- a/src/ArduinoJson/version.hpp +++ b/src/ArduinoJson/version.hpp @@ -4,8 +4,8 @@ #pragma once -#define ARDUINOJSON_VERSION "6.21.3" +#define ARDUINOJSON_VERSION "6.21.5" #define ARDUINOJSON_VERSION_MAJOR 6 #define ARDUINOJSON_VERSION_MINOR 21 -#define ARDUINOJSON_VERSION_REVISION 3 -#define ARDUINOJSON_VERSION_MACRO V6213 +#define ARDUINOJSON_VERSION_REVISION 5 +#define ARDUINOJSON_VERSION_MACRO V6215