cargo.toml
actix-web = { version = "^0.7", features = ["ssl"] }
diesel = { version = "^1.4", features = ["mysql", "chrono", "r2d2"] }
dotenv = "0.13.0"
serde = "1.0.80"
serde_derive = "1.0.80"
serde_json = "1.0.32"
chrono = { version = "0.4.6", features = ["serde"] }
futures = "^0.1"
env_logger = "^0.6"
failure = "^0.1.5"
Model:
#[derive(Deserialize, Serialize, Insertable, Debug)]
#[table_name = "answers"]
pub struct AnswerForm {
pub question_id: i32,
pub title: String,
pub user_id: i32,
pub created: NaiveDateTime,
}
Schema:
CREATE TABLE answers (
id INT PRIMARY KEY AUTO_INCREMENT,
question_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
user_id INT NOT NULL,
created TIMESTAMP NOT NULL
)
For a json input like this:
{
"question_id": 1,
"title": "something",
"user_id": 1,
"created": "2007-04-05T14:30Z"
}
I am getting error:
Error occured during request handling: Json deserialize error: input contains invalid characters at line 5 column 34
This could be a problem in chrono I am not sure.
This error is not from serde_json. I would recommend minimizing a failing test case to narrow down the problem.
Ah. Got the problem. NaiveDateTime expects _ISO 8601 combined date and time without timezone._ and I was passing the date in incorrect format. The timezone was mentioned and second was not mentioned. The correct format is 2007-04-05T14:30:30. Thanks.
Nice! Glad you figured it out.
Most helpful comment
Ah. Got the problem.
NaiveDateTimeexpects _ISO 8601 combined date and time without timezone._ and I was passing the date in incorrect format. The timezone was mentioned and second was not mentioned. The correct format is2007-04-05T14:30:30. Thanks.