Open fzuuzf opened 1 month ago
Thanks for bringing this up. Right now BEVE doesn't adhere to skip_null_members
, which it should. Will keep this issue alive until support has been added.
A fix:
diff --git a/include/glaze/beve/read.hpp b/include/glaze/beve/read.hpp
index a3abe46..c21ef1e 100644
--- a/include/glaze/beve/read.hpp
+++ b/include/glaze/beve/read.hpp
@@ -1108,15 +1108,8 @@ namespace glz
GLZ_END_CHECK();
const auto tag = uint8_t(*it);
- if (tag == tag::null) {
+ if (tag == tag::null)
++it;
- if constexpr (is_specialization_v<T, std::optional>)
- value = std::nullopt;
- else if constexpr (is_specialization_v<T, std::unique_ptr>)
- value = nullptr;
- else if constexpr (is_specialization_v<T, std::shared_ptr>)
- value = nullptr;
- }
else {
if (!value) {
if constexpr (is_specialization_v<T, std::optional>)
So, we actually want to set the value to null if a null value is read in. The reason why your BEVE and JSON do not align right now is that by default JSON serialization uses the option skip_null_members
, which means your JSON message will not set the elements to null. If you set skip_null_members
to false
then the JSON and BEVE would act the same.
The code you posted isn't really a fix. What is needed is skip_null_members
support for BEVE so that null fields don't get written and thus don't set your optionals to null when read in.
Hi Stephen,
this code:
triggers the last assert here for gcc-14, clang-1[89] on ubuntu 24.04.
Thanks, Karsten