-
Notifications
You must be signed in to change notification settings - Fork 577
Add Serde Impls to json-like prost-types Structs
#1302
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
base: master
Are you sure you want to change the base?
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.
Thank you for your contribution. This looks like a good first step for a JSON implementation. I would like to see the following additions:
- Describe the
serdefeature flag in thelib.rsdoc comment. This has to at least say that not all types are serializable - Please add some tests to prevent future regressions
- Can you confirm that this serialization follows the official ProtoJSON format? It would be super if you could confirm that in a test case.
I've added a description. Please let me know if it's insufficient.
Done.
Eyeballing it, it seems like it won't make something invalid for serialization, but for deserialization it looks like converting |
Documentation for `Value` says "Absence of any variant indicates an error."
|
@caspermeijn Is this sufficient? Note that I've added a line in the config that ignores the unused dependency false positive. |
This allows the ListValue, Struct, and Value types to be serialized with serde by enabling a new "serde" crate feature.
This code was originally written by ChatGPT (and me) in July 2024, back when I would not have been able to write it entirely myself. It had dependency issues and a strange nested Visitor implementation, but it worked well enough to use privately. I've learned a lot of Rust in a year, and went over it today and was able to cut out 70 lines of ai cruft nonsense and use a crate feature. The reason I'm upstreaming this now is because I saw that the "arbitrary" feature was added which looks similar to serde. I briefly tested this in my game's staging deployment and it seems to work well enough to not cause any new issues compared to the previous crufted ai implementation.
Also of interest: Add
#[derive(serde::Serialize, serde::Deserialize)]to protobuf generated structs