Skip to content

Avoid erroring on nullable value types#2394

Merged
stephenberry merged 1 commit intomainfrom
nullable-value-types
Mar 22, 2026
Merged

Avoid erroring on nullable value types#2394
stephenberry merged 1 commit intomainfrom
nullable-value-types

Conversation

@stephenberry
Copy link
Copy Markdown
Owner

@stephenberry stephenberry commented Mar 22, 2026

Fix error_on_missing_keys for value types wrapping nullable types

Fixes #2389

When a struct uses glaze::value to serialize as one of its members (a "value type"), and that member is nullable (e.g. std::optional), error_on_missing_keys incorrectly treated the field as required. This is because required_fields() checked nullability on the outer struct rather than the underlying type it serializes as.

Changes

include/glaze/core/reflect.hpp — Added a glaze_value_t branch to required_fields() that unwraps the value type via remove_meta_wrapper_t and checks nullability on the inner type. Applied in both the meta_has_requires_key path and the default path.

tests/json_test/json_test.cpp — Added a test verifying that a missing value-type field backed by std::optional does not produce a missing_key error, while non-nullable required fields still do.

@stephenberry stephenberry merged commit f7a6b6b into main Mar 22, 2026
47 of 48 checks passed
@stephenberry stephenberry deleted the nullable-value-types branch March 22, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Value types" pointing to nullable types still cause an error when error_on_missing_keys is set

1 participant