-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and improve NamedTuple
deserialization from JSON and YAML
#12008
Refactor and improve NamedTuple
deserialization from JSON and YAML
#12008
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it wouldn't be easier to always use an uninitailized value and keep track if it was found. And only apply nil handling for nilable properties when constructing the final tuple.
src/json/from_json.cr
Outdated
%var{key.id} = uninitialized typeof(begin | ||
value = uninitialized self | ||
value[{{ key.symbolize }}] | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this work?
%var{key.id} = uninitialized typeof(begin | |
value = uninitialized self | |
value[{{ key.symbolize }}] | |
end) | |
%var{key.id} = uninitialized {{ type }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put a comment around why we do it this way. I think I made the exact same comment in a previous PR but now I can't remember why doing it the way @straight-shoota (and previously me) suggest is not a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @HertzDevil 🙏
NamedTuple
s that use file-private value types.Fixes compilation error for deserialization of emptyNamedTuple
s.