dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Why is it trying to deserialize a map instead of an enum? #415

Open Masber opened 8 months ago

Masber commented 8 months ago

Deal serde_yaml community,

I have these structs and entity:

#[derive(Deserialize, Serialize, Debug)]
pub struct Ims {
    name: String,
    r#type: String,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct Product {
    name: String,
    version: String,
    r#type: String,
}

#[derive(Deserialize, Serialize, Debug)]
pub enum ImageBase {
    Ims { ims: Ims },
    Product { product: Product },
    ImageRef { image_ref: String },
}

#[derive(Deserialize, Serialize, Debug)]
pub struct SatFileImage {
    pub name: String,
    pub base: ImageBase,
    pub configuration: Option<String>,
    pub configuration_group_names: Option<Vec<String>>,
    pub ref_name: Option<String>,
    pub description: Option<String>,
}

I have a yaml like

- name: my-name
  base:
    ims:
      name: my-name
      type: image
  configuration: my-configuration
  configuration_group_names:
  - Compute

And this fails with the following error:

Err(
    Error("invalid type: map, expected a Value::Tagged enum"),
)

Any idea why am I getting this error?

kind regards