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

DateTimeWithTimeZone does not implement Serialize and Deserialize #319

Closed
YoshieraHuang opened this issue Nov 15, 2021 · 6 comments · Fixed by #320
Closed

DateTimeWithTimeZone does not implement Serialize and Deserialize #319

YoshieraHuang opened this issue Nov 15, 2021 · 6 comments · Fixed by #320
Assignees

Comments

@YoshieraHuang
Copy link
Contributor

Hi. sea-orm use DateTimeWithTimeZone in Model to map TIMESTAMPTZ in postgresql. DateTimeWithTimeZone is just an alias of type chrono::DateTime<chrono::FixedOffset>, which has already implemented Serialze and Deserialize traits in chrono crate. However, the compiler says DateTimeWithTimeZone does not implement Serialize and Deserialize in the generated scripts. It is weird. My rust version is 1.56.1, and the sea-orm is synced with the master branch in this repository.

@billy1624
Copy link
Member

Hey @YoshieraHuang, would you mind showing us the detail compile errors?

@YoshieraHuang
Copy link
Contributor Author

Hey @YoshieraHuang, would you mind showing us the detail compile errors?

This is my scripts:

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "materials")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    pub name: String,
    #[sea_orm(column_type = "Text", nullable)]
    pub description: Option<String>,
    pub tag_ids: Vec<u8>,
}

And this is the error:

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Serialize` is not satisfied
    --> src/materials/entity/material_tags.rs:11:5
     |
11   |     pub created_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Serialize` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `materials::_::_serde::ser::SerializeStruct::serialize_field`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/ser/mod.rs:1893:5
     |
1893 | /     fn serialize_field<T: ?Sized>(
1894 | |         &mut self,
1895 | |         key: &'static str,
1896 | |         value: &T,
1897 | |     ) -> Result<(), Self::Error>
1898 | |     where
1899 | |         T: Serialize;
     | |_____________________^

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Serialize` is not satisfied
    --> src/materials/entity/material_tags.rs:12:5
     |
12   |     pub updated_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Serialize` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `materials::_::_serde::ser::SerializeStruct::serialize_field`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/ser/mod.rs:1893:5
     |
1893 | /     fn serialize_field<T: ?Sized>(
1894 | |         &mut self,
1895 | |         key: &'static str,
1896 | |         value: &T,
1897 | |     ) -> Result<(), Self::Error>
1898 | |     where
1899 | |         T: Serialize;
     | |_____________________^

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Deserialize<'_>` is not satisfied
    --> src/materials/entity/material_tags.rs:11:5
     |
11   |     pub created_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `next_element`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/de/mod.rs:1703:5
     |
1703 | /     fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error>
1704 | |     where
1705 | |         T: Deserialize<'de>,
     | |____________________________^

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Deserialize<'_>` is not satisfied
    --> src/materials/entity/material_tags.rs:12:5
     |
12   |     pub updated_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `next_element`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/de/mod.rs:1703:5
     |
1703 | /     fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error>
1704 | |     where
1705 | |         T: Deserialize<'de>,
     | |____________________________^

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Deserialize<'_>` is not satisfied
    --> src/materials/entity/material_tags.rs:11:5
     |
11   |     pub created_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `next_value`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/de/mod.rs:1842:5
     |
1842 | /     fn next_value<V>(&mut self) -> Result<V, Self::Error>
1843 | |     where
1844 | |         V: Deserialize<'de>,
     | |____________________________^

error[E0277]: the trait bound `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>: Deserialize<'_>` is not satisfied
    --> src/materials/entity/material_tags.rs:12:5
     |
12   |     pub updated_at: DateTimeWithTimeZone,
     |     ^^^ the trait `Deserialize<'_>` is not implemented for `chrono::datetime::DateTime<chrono::offset::fixed::FixedOffset>`
     |
note: required by `next_value`
    --> /home/jasper/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/serde-1.0.130/src/de/mod.rs:1842:5
     |
1842 | /     fn next_value<V>(&mut self) -> Result<V, Self::Error>
1843 | |     where
1844 | |         V: Deserialize<'de>,
     | |____________________________^

@YoshieraHuang
Copy link
Contributor Author

According to chronotope/chrono#515, the serde feature in chrono must be enabled. However chronotope/chrono#598 gave an negative message. I will figure this out.

@billy1624
Copy link
Member

billy1624 commented Nov 15, 2021

According to chronotope/chrono#515, the serde feature in chrono must be enabled.

Correct! Should be fixed by #320

However chronotope/chrono#598 gave an negative message. I will figure this out.

I'm not sure about this

@YoshieraHuang
Copy link
Contributor Author

According to chronotope/chrono#515, the serde feature in chrono must be enabled.

Correct! Should be fixed by #320

However chronotope/chrono#598 gave an negative message. I will figure this out.

I'm not sure about this

The chrono/serde feature works for me! Thank you for your quick fix!

@billy1624
Copy link
Member

Welcome! :)

tyt2y3 added a commit that referenced this issue Nov 16, 2021
`with-json` feature requires `chrono/serde`
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

Successfully merging a pull request may close this issue.

2 participants