Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

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

Open
Masber opened this issue Mar 8, 2024 · 0 comments
Open

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

Masber opened this issue Mar 8, 2024 · 0 comments

Comments

@Masber
Copy link

Masber commented Mar 8, 2024

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


@Masber Masber changed the title serialize struct with enum fails How to serialize enums? Mar 8, 2024
@Masber Masber changed the title How to serialize enums? Why is it trying to serialize a map when I expect an enum? Mar 8, 2024
@Masber Masber changed the title Why is it trying to serialize a map when I expect an enum? Why is it trying to deserialize a map instead of an enum? Mar 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant