Fix volatile bool serialized as 1 or 0

Ported from 5d1d2721d1
This commit is contained in:
Benoit Blanchon
2024-01-10 13:30:26 +01:00
parent 315cc722e9
commit a7bfc2212c
3 changed files with 10 additions and 1 deletions

View File

@ -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)
------

View File

@ -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);

View File

@ -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();
}