Skip to content
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

Code generation with serde(default) #524

Closed
Freydal opened this issue Sep 11, 2020 · 4 comments
Closed

Code generation with serde(default) #524

Freydal opened this issue Sep 11, 2020 · 4 comments

Comments

@Freydal
Copy link

Freydal commented Sep 11, 2020

It may be a moot point in context of #519, but support for optional fields in JSON input would be useful.

I'm not sure if there is a good clean workaround so I opted to just fork and hack the option in quickly.

@stepancheg
Copy link
Owner

Can you please explain, what exactly are you proposing?

@Freydal
Copy link
Author

Freydal commented Sep 14, 2020

Sorry for the confusion.

If you attempt to deserialize json for a proto struct that has 3 fields and the json only has 2 of them present, for example, you will fail in error due to the missing field. I feel it is beneficial to allow for the presence of serde(default) to configure serde_json to use default values for potentially missing items in the json during deserialization. The solution may not be require all fields to be present despite the protobuf definition.

Due to #519 I thought in the long time another solution to this issue may be warranted due to native json support. In the short time I hacked the option in to get me moving in this fork commit.

@stepancheg
Copy link
Owner

I see, thanks for the explanation. Well, I know only a little about serde. Your patch looks right, but I'd avoid risking breaking backwards compat unless there are good reasons to. Please let me know if this is needed in rust-protobuf v2. Otherwise better just drop serde support in v3.

@stepancheg
Copy link
Owner

rust-protobuf version 2 is now is maintenance mode.

rust-protobuf version 3:

  • remove serde support
  • instead users can supply custom per type, per field annotations
  • has native JSON support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants