Skip to content

Add serde feature flag to prost-types - #1252

Open
allada wants to merge 1 commit into
tokio-rs:masterfrom
allada:add-serde-support
Open

Add serde feature flag to prost-types#1252
allada wants to merge 1 commit into
tokio-rs:masterfrom
allada:add-serde-support

Conversation

@allada

@allada allada commented Feb 27, 2025

Copy link
Copy Markdown

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

@caspermeijn caspermeijn left a comment

Copy link
Copy Markdown
Member

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 #1081 will be a breaking change. Because the JSON names change.

Comment thread prost-types/Cargo.toml Outdated
Comment on lines +20 to +21
serde_serialize = ["std", "dep:serde"]
serde_deserialize = ["std", "dep:serde"]

Copy link
Copy Markdown
Member

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.

Comment thread prost-types/Cargo.toml Outdated
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
Copy Markdown
Member

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

allada commented Mar 17, 2025

Copy link
Copy Markdown
Author
  • 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.

@spy16x

spy16x commented Jul 16, 2025

Copy link
Copy Markdown

Any update on this? Or any alternatives possible for this? I really need this feature 🙂

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

3 participants