Closed Tenshock closed 1 year ago
The current workaround is to use serde rename
.
use serde_json::json;
use serde_valid::json::FromJsonValue;
use serde_valid::Validate;
#[derive(serde::Deserialize, Validate)]
#[rule(sample_rule(_type))]
struct MyStruct {
#[serde(rename = "type")]
pub _type: bool,
}
fn sample_rule(r#type: &bool) -> Result<(), serde_valid::validation::Error> {
Ok(())
}
#[test]
fn test() -> Result<(), Box<dyn std::error::Error>> {
let my_struct = MyStruct { _type: true };
assert!(my_struct.validate().is_ok());
assert_eq!(
MyStruct::from_json_value(json!({"type": true}))?._type,
my_struct._type
);
Ok(())
}
The field name "type" seems to be an Issue proposed in many crates. A special workaround is provided.
@Tenshock
I released v0.16.3.
Hi, thanks for this beautiful crate.
I found a bug I htink in the way the crate interprets attributes. The following code produces the following error:
I know I can check the attribute
r#type
directly with#[validate(...)]
but my use case implies multiples attributes.