Merged
Conversation
This was referenced Mar 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
glz::customgetter returning nullopt not being omittedFixes #2386
When a
glz::objectfield usesglz::custom<setter, getter>and the getter returns a nullable type (e.g.std::optional<T>), the field was always serialized — even when the getter returnedstd::nullopt. Withskip_null_members = true(the default), the expected behavior is to omit the field entirely, consistent with how plainstd::optionalmembers and nullable lambdas are handled.The root cause is that the skip-null check in the object write path operates on
field_t, which for custom fields iscustom_t<...>— a wrapper that does not satisfynull_t. The nullable return type of the getter is never inspected.Changes
include/glaze/core/reflect.hppcustom_getter_returns_nullable<V>(): compile-time trait that inspects the getter's return type across all supported forms (member function pointers, member object pointers,std::functionmembers, concrete lambdas, generic lambdas, context-taking invocables).custom_getter_is_null(): runtime helper that invokes the getter and checks whether the result is null. Reused by all three format writers.maybe_skippedto includecustom_tfields whose getters return nullable types, so the dynamic-skip path is entered when needed.include/glaze/json/write.hppelse if constexprbranch forcustom_twith nullable getter in the object field write loop. Invokes the getter viacustom_getter_is_null()and skips the field if null.include/glaze/cbor/write.hppinclude/glaze/beve/write.hpptests/json_test/nullable_lambda_test.cppglz::custom<setter, getter>with anstd::optional<std::string>getter:std::nullopt→ field omittedskip_null_members = false→ field written asnull