-
Notifications
You must be signed in to change notification settings - Fork 274
Telegram struct serializing similar to original (skip empty/defaults) #864
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
Telegram struct serializing similar to original (skip empty/defaults) #864
Conversation
|
@WaffleLapkin PR still not completed. |
WaffleLapkin
left a comment
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.
The general approach looks good to me! Most/all of these annotations I just forgot to add 😅
While round-tripping json through our structures preserving the exact form is not our primary goal, it's still good to have.
Also look out for our custom de/serialize impls and more typed reinterpretations (an enum instead of bunch of options, etc) — they historically caused a few bugs and can easily influence round-tripability.
| /// For messages with a caption, special entities like usernames, URLs, | ||
| /// bot commands, etc. that appear in the caption. | ||
| #[serde(default)] | ||
| #[serde(skip_serializing_if = "Vec::is_empty", default = "Vec::new")] |
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.
BTW you don't need = "Vec::new", since Vec implements Default. If you could replace existing mentions of default = "Vec::new " with default that would be nice.
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.
Agree, fixed
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 don't think this is fixed... have you maybe forgot to push the commit?
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.
Yes
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.
@Olegt0rr you still did not address this comment, there are still default = "Vec::new" in the message.rs
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.
@hirrolot I think this still wasn't addressed
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.
Just removed redundant "Vec::new"
|
Ping, @Olegt0rr do you still intend to work on this? |
|
@WaffleLapkin, could you review this PR? |
WaffleLapkin
left a comment
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.
Thanks!
Close #863
Solution
serde_with_macros::skip_serializing_noneto every Telegram struct by default to exclude empty fieldsskip_serializing_if = "std::ops::Not::not"to excludeFalseto "True or absent" fieldsskip_serializing_if = "Vec::is_empty"to exclude empty[ ]