You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rfl::cereal::Reader::is_empty: return _var.archive_ == nullptr; (always non-null during read)
Compare with rfl::parsing::schemaful::OptionalReader, which returns the empty state directly without calling _r.is_empty(_var) because the schema/discriminant already identifies the null branch. Guarding the is_empty check with if constexpr (!schemaful::IsSchemafulReader<R>) in ParserMonostate::read would fix all three formats:
structOrder {
std::variant<std::monostate, std::string, int> price;
};
// 1. Write omits `price` -> "{}"constauto json =
rfl::json::write<rfl::AddTagsToVariants>(Order{.price = std::monostate{}});
// 2. JSON Schema still puts "price" in "required":// "properties":{"price":{"anyOf":[{"type":"object","properties":{"monostate":{"type":"null"}},"required":["monostate"]}, ...]}},"required":["price"]constauto schema = rfl::json::to_schema<Order, rfl::AddTagsToVariants>();
// -> `json` ("{}") fails validation against `schema`!// 3. Explicit null also fails to read (expects {"price":{"monostate":null}}):constauto res = rfl::json::read<Order, rfl::AddTagsToVariants>(R"({"price":null})");
Why this happens:
is_required / is_empty don't take ProcessorsType into account, so NamedTupleParser::write treats price as optional and omits it when holding std::monostate.
Under rfl::AddTagsToVariants / rfl::AddNamespacedTagsToVariants, ParserVariant::to_schema wraps each alternative in VariantAlternativeWrapper, so the first Type::AnyOf branch is a Type::Object (e.g. {"monostate": null}), not a bare Type::Null.
is_optional() in src/rfl/json/to_schema.cpp only checks rfl::holds_alternative<parsing::schema::Type::Null>(_v.types_.front().variant_), which returns false, emitting "required": ["price"].
As a result, the serialized output {} does not validate against the generated JSON Schema, and {"price":null} is rejected on read. Serialization, deserialization, and schema generation should agree for tagged variants (either handling tagged-variant Null wrappers consistently, or not treating tagged monostate variants as omitted optionals).
(Feedback from an AI reviewer.)
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #749