Enum variant aliases don't work
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
Here is a failing example demonstrating that enum variant aliases are not taken into account. It also shows a divergence in behavior compared to using serde_json directly.
#[derive(Debug, serde::Deserialize)]
enum TestEnum {
#[serde(alias = "f")]
Foo,
#[serde(alias = "b")]
Bar,
}
#[derive(Debug, serde::Deserialize)]
struct Wrapper {
test: TestEnum,
}
let json = r#"{"test": "f"}"#;
let w: Wrapper = serde_json::from_str(json).unwrap();
println!("{:?}", w);
let w: Wrapper = config::Config::builder()
.add_source(config::File::from_str(json, config::FileFormat::Json))
.build()
.unwrap()
.try_deserialize()
.unwrap();
println!("{:?}", w);
Output:
Wrapper { t: Foo }
called `Result::unwrap()` on an `Err` value: enum TestEnum does not have variant constructor f
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
Start with the failing Rust example and compare the serde_json deserialization path with config::Config::builder(), especially the JSON source and try_deserialize steps. Trace how enum variant names are resolved; done means serde aliases such as "f" and "b" deserialize through config as they do with serde_json.
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
- 42/100