Skip to content

Commit

Permalink
Fix volatile bool serialized as 1 or 0
Browse files Browse the repository at this point in the history
Ported from 5d1d272
  • Loading branch information
bblanchon committed Jan 10, 2024
1 parent 315cc72 commit a7bfc22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HEAD

* Fix "no matching function" with `JsonObjectConst::operator[]` (issue #2019)
* Remove unused files in the PlatformIO package
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)

v7.0.0 (2024-01-03)
------
Expand Down
7 changes: 7 additions & 0 deletions extras/tests/JsonVariant/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ TEST_CASE("volatile") {
JsonDocument doc;
JsonVariant variant = doc.to<JsonVariant>();

SECTION("volatile bool") { // issue #2029
volatile bool f = true;
variant.set(f);
CHECK(variant.is<bool>() == true);
CHECK(variant.as<bool>() == true);
}

SECTION("volatile int") {
volatile int f = 42;
variant.set(f);
Expand Down
3 changes: 2 additions & 1 deletion src/ArduinoJson/Variant/VariantRefBaseImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ VariantRefBase<TDerived>::operator[](const TString& key) const {
template <typename TDerived>
template <typename T>
inline bool VariantRefBase<TDerived>::set(const T& value) const {
Converter<T>::toJson(value, getOrCreateVariant());
Converter<typename detail::remove_cv<T>::type>::toJson(value,
getOrCreateVariant());
auto resources = getResourceManager();
return resources && !resources->overflowed();
}
Expand Down

0 comments on commit a7bfc22

Please sign in to comment.