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

Support adding prefix/suffix to flattened fields #2738

Closed
orclev opened this issue May 12, 2024 · 2 comments
Closed

Support adding prefix/suffix to flattened fields #2738

orclev opened this issue May 12, 2024 · 2 comments

Comments

@orclev
Copy link

orclev commented May 12, 2024

In Java the Jackson serialization library has a feature similar to flatten which is the @JsonUnwrapped annotation. Unlike flatten however it supports a pair of optional parameters prefix and suffix which are arbitrary String values that will be prepended or appended respectively to the flattened fields names. This is very useful when you have multiple instances of some struct that you want to flatten but you want to avoid name collisions. It would be great if serde could support a similar prefix and suffix argument to flatten.

@dtolnay
Copy link
Member

dtolnay commented May 12, 2024

Prefix is supported by using https://docs.rs/serde_with/3.8.1/serde_with/macro.with_prefix.html.

Suffix was previously requested in jonasbb/serde_with#381 but there doesn't seem to be demand.

@orclev
Copy link
Author

orclev commented May 12, 2024

Ah nice, I had looked through the docs for flatten and didn't see any way to add a prefix, I didn't realize it was an entirely different attribute. Thanks.

@orclev orclev closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants