Serde alias not working
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
Im expecting to put alias to each fields in a struct where the alias name are the keys from os env
#[derive(Debug, Deserialize, Clone)]
pub struct BuildInfo {
#[serde(alias = "VERSION")]
pub app_version: String,
}
in my os env:
VERSION=1.2.3
When I build with:
let builder = Config::builder().add_source(Environment::default()).build();
builder.unwrap().try_deserialize::<BuildInfo>().unwrap()
I got panic error: value: missing field app_version``
If I change with serde rename I got:
value: missing field VERSION
it works if I just change the letter case like from VERSION to version, but I need way to map this.
How to map easily from os env with different keys name to structs with different keys name?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown BuildInfo struct, VERSION environment variable, and Environment source. Trace how environment keys are normalized and passed to serde, then verify that the intended mapping from VERSION to app_version is either supported or clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100