Skip to content

Add serde feature flag to prost-types #1252

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

allada
Copy link

@allada allada commented Feb 27, 2025

Adds "serde_deserialize", "serde_serialize" and "serde" flags to prost-types. This will allow users to enable serde support to the well known types.

closes #852

@allada allada force-pushed the add-serde-support branch 4 times, most recently from 391a5e6 to 67f74b1 Compare February 27, 2025 21:56
Copy link
Collaborator

@caspermeijn caspermeijn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I miss documentation of the feature flag
  • What does this mean for stability guarantees?
  • When you serialize these messages to JSON, it will not be ProtoJSON compatible.
  • If we merged this, then WIP: Add json (serde) support #1081 will be a breaking change. Because the JSON names change.

Comment on lines 20 to 21
serde_serialize = ["std", "dep:serde"]
serde_deserialize = ["std", "dep:serde"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it important to split the feature? The compiler is smart enough to remove unused code from the binary, right? I suggest having a single serde feature.


[dependencies]
prost = { version = "0.13.5", path = "../prost", default-features = false, features = ["prost-derive"] }
arbitrary = { version = "1.4", features = ["derive"], optional = true }
chrono = { version = "0.4.34", default-features = false, optional = true }
serde = { version = "1.0.218", default-features = false, optional = true, features = ["derive", "std"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is std feature needed?

Adds "serde_deserialize", "serde_serialize" and "serde" flags to
prost-types. This will allow users to enable serde support to the
well known types.

closes tokio-rs#852
@allada allada force-pushed the add-serde-support branch from 67f74b1 to ea27b80 Compare March 17, 2025 17:09
@allada
Copy link
Author

allada commented Mar 17, 2025

  • I miss documentation of the feature flag
    Done.
  • What does this mean for stability guarantees?
    (depends on response)
  • When you serialize these messages to JSON, it will not be ProtoJSON compatible.
    Yes, but serde provides more than just json serialization. Maybe we can add note to the documentation stating that json support in serde is not the same as proto's json serialization?
  • If we merged this, then WIP: Add json (serde) support #1081 will be a breaking change. Because the JSON names change.
    One idea is to gate this feature behind serde_experimental (or similar) to give flexibility of breaking changes while proto's json and serde's json gets hammered out?

However, it probably is best to stabilize proto-json and it'd likely get serde naturally. This would dramatically reduce the chance of creating a breaking change.

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

Successfully merging this pull request may close these issues.

serde support for prost-types
2 participants