Skip to content

Nullable value write skipping#2398

Merged
stephenberry merged 1 commit intomainfrom
nullable-value-write-skipping
Mar 24, 2026
Merged

Nullable value write skipping#2398
stephenberry merged 1 commit intomainfrom
nullable-value-write-skipping

Conversation

@stephenberry
Copy link
Copy Markdown
Owner

@stephenberry stephenberry commented Mar 23, 2026

Fix skip_null_members for glaze_value_t wrapping nullable types

Fixes #2397

When a struct field uses glaze::value to expose a nullable inner type (e.g. std::optional, std::unique_ptr), the skip_null_members option was not skipping the field during writing. The null check was only performed on the outer wrapper type, which is not itself nullable.

Changes

include/glaze/core/reflect.hpp

  • Added glaze_value_is_nullable<V>() — compile-time check for whether a glaze_value_t wraps a nullable inner type.
  • Added is_glaze_value_field_null<T, I>(value, t) — runtime null check that unwraps the value type and tests the inner value.
  • Updated maybe_skipped to recognize nullable value types so the skip code path is entered.

include/glaze/json/write.hpp, cbor/write.hpp, beve/write.hpp

  • Added an else if branch in each object-member write loop that calls the new helpers to skip null value-type fields. CBOR and BEVE each have two sites (member-count pass and write pass).

Tests

  • std::optional<int> inner type — null skipped, non-null written
  • std::unique_ptr<int> inner type — exercises the !bool() null-check path
  • Multiple nullable value-type fields with mixed null/non-null
  • skip_null_members = false — null explicitly written as null
  • JSON and BEVE round-trip (write then read back)

@stephenberry stephenberry merged commit 400c479 into main Mar 24, 2026
48 of 49 checks passed
@stephenberry stephenberry deleted the nullable-value-write-skipping branch March 24, 2026 01:32
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 are still written even when skip_null_members is enabled and they are null

1 participant