Add custom type handling for nullable fields in JSON serialization#2388
Closed
Zetonem wants to merge 1 commit intostephenberry:mainfrom
Closed
Add custom type handling for nullable fields in JSON serialization#2388Zetonem wants to merge 1 commit intostephenberry:mainfrom
Zetonem wants to merge 1 commit intostephenberry:mainfrom
Conversation
Owner
|
@Zetonem, thanks for submitting this. I see a few completeness issues. I'll either contribute to this PR, or open a similar one and close this. But, this is helpful to see an initial solution, thanks! |
Owner
|
I just merged in a similar fix with #2390, so I'm closing this. But, thanks for contributing and feel free to keep posting issues and PRs! |
Author
Thank you! |
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.
Summary
When a glz::object field uses glz::custom<setter, getter> and the getter returns std::optional that is std::nullopt, Glaze currently serializes the field as "field": null instead of omitting the field (under skip_null_members=true). This PR adds a regression test and fixes the JSON writer so the field is skipped when the custom getter produces a null/empty optional.
Changes
Expanded the maybe_skipped condition so that when skip_null_members=true, glz::custom_t fields are considered “potentially skippable”, allowing the runtime logic in json/write.hpp to run.
Issue
#2386