Hi
I am validating using the crate "validator",
It works fine, but I don't know how to convert the errors to json
#[derive(Debug, Validate, serde::Serialize, serde::Deserialize)]
struct UserData {
#[validate(length(min = 2, max = 20))]
name: String,
#[validate(required)]
allow_cookies: Option<bool>,
#[validate(email)]
mail: String
}
let udata = UserData{
...
}
udata.validate()?;
The error it shows me in my API is this, which is not a valid json
{
"data": null,
"errors": [
{
"message": "ValidationErrors({\"last_name\": Field([ValidationError { code: \"length\", message: None, params: {\"min\": Number(1), \"max\": Number(10), \"value\": String(\"\")} }])})",
}
]
}
Crates
serde = { version = "1.0.117", features = ["derive"] }
serde_json = "1.0"
validator = { version = "0.12", features = ["derive"] }
How can I convert the error messages to json?