Add URI::Params::Field ignore options#17037
Open
RoySerbi wants to merge 4 commits into
Open
Conversation
straight-shoota
approved these changes
Jun 1, 2026
Sija
reviewed
Jun 1, 2026
ysbaddaden
approved these changes
Jun 1, 2026
Member
|
There is already #17029 pending for the same feature and the implementation looks better: #16873 (comment) |
Mirrors the JSON::Serializable convention: when ignore_serialize: is a
literal 'true', the field is skipped at compile time (existing behaviour).
When it's any other Crystal expression, the emit is wrapped in
'unless {{expr}}' so the expression is evaluated at runtime, allowing
conditional serialization based on instance state, e.g.
@[URI::Params::Field(ignore_serialize: internal)]
@token : String
See src/json/serialization.cr for the matching pattern in
JSON::Serializable. Updates docstring and adds a spec for the
runtime-expression case.
Author
|
@straight-shoota Good catch on the parity with #17029 — looking at
The deserialization side is unchanged (still compile-time only for |
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.
Resolves #16873.
This adds the same basic field-skipping options to
URI::Params::Fieldthat are already available onJSON::FieldandYAML::Field:ignore: trueskips both serialization and deserializationignore_serialize: trueskips#to_www_formignore_deserialize: trueskips.from_www_formI also updated the
URI::Params::Serializabledocs and added specs covering each case.Local check:
git diff --checkI could not run the Crystal specs locally because this Windows environment does not have the Crystal compiler installed.