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

skip/skip_if are not working for Enum, Struct and Vec #152

Closed
lbenini opened this issue Dec 28, 2022 · 1 comment
Closed

skip/skip_if are not working for Enum, Struct and Vec #152

lbenini opened this issue Dec 28, 2022 · 1 comment

Comments

@lbenini
Copy link
Contributor

lbenini commented Dec 28, 2022

Description

skip_serializing and skip_serializing_if are not working for Enum, Struct (children of the root) and Vec.

How to procedure

The following snippets of code can be inserted in the skip.rs test suite to reproduce the bug for skip_serializing

#[test]
fn skip_serializing_for_nested_struct() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing)]
    skipped_serializing: XmlStructChild,
  }

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "child")]
  pub struct XmlStructChild {
  }

  let model = XmlStruct {
    skipped_serializing: XmlStructChild{},
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

#[test]
fn skip_serializing_for_enum() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing)]
    skipped_serializing: XmlEnum,
  }

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "child")]
  pub enum XmlEnum {
    Ok
  }

  let model = XmlStruct {
    skipped_serializing: XmlEnum::Ok,
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

#[test]
fn skip_serializing_for_vec() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing)]
    skipped_serializing: Vec<i8>,
  }

  let model = XmlStruct {
    skipped_serializing: vec![1,2,3],
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

the following snippets can be used in serializing_if.rs file to reproduce the conditional serialization issue

#[test]
fn skip_serializing_if_for_nested_struct() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing_if="check_child")]
    skipped_serializing: XmlStructChild,
  }
  impl XmlStruct
  {
    fn check_child(&self, _child:&XmlStructChild)->bool
    {
      true
    }
  }
  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "child")]
  pub struct XmlStructChild {
  }

  let model = XmlStruct {
    skipped_serializing: XmlStructChild{},
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

#[test]
fn skip_serializing_if_for_enum() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing_if="check_enum")]
    skipped_serializing: XmlEnum,
  }
  impl XmlStruct
  {
    fn check_enum(&self, _child:&XmlEnum)->bool
    {
      true
    }
  }
  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "child")]
  pub enum XmlEnum {
    Ok
  }

  let model = XmlStruct {
    skipped_serializing: XmlEnum::Ok,
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

#[test]
fn skip_serializing_if_for_vec() {
  init();

  #[derive(YaSerialize, PartialEq, Debug)]
  #[yaserde(rename = "base")]
  pub struct XmlStruct {
    #[yaserde(skip_serializing_if="check_vec")]
    skipped_serializing: Vec<i8>,
  }
  impl XmlStruct
  {
    fn check_vec(&self, _child:&Vec<i8>)->bool
    {
      true
    }
  }
  let model = XmlStruct {
    skipped_serializing: vec![1,2,3],
  };

  let content = "<base />";
  serialize_and_validate!(model, content);
}

Analisys

The issue is located expand_struct.rs where the conditions are generated, but never kept in consideration for Enum, Struct and Vec

Solutions

I'm working on pull request that fix the issue

Notes

Related, but different or partial issues are:
#131
#139

@lbenini
Copy link
Contributor Author

lbenini commented Jan 4, 2023

With the merge of #153 this is now solved

@lbenini lbenini closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant