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

Datetime fields are not serialized by .into_json() on queries #530

Closed
junbl opened this issue Feb 14, 2022 · 5 comments · Fixed by #539
Closed

Datetime fields are not serialized by .into_json() on queries #530

junbl opened this issue Feb 14, 2022 · 5 comments · Fixed by #539
Assignees

Comments

@junbl
Copy link
Contributor

junbl commented Feb 14, 2022

Description

When using the .into_json() method to load the result of a query into a JsonValue object, the resulting JSON is missing any date/datetime fields (chrono Date/DateTime<Tz> objects) that were present in the model.

Steps to Reproduce

  1. Create a model/database with date and/or datetime fields.
  2. Query the data in that model.
  3. Call .into_json() on the result.

Expected Behavior

The JsonValue object will include String representations of datetimes in YYYY-MM-DDTHH:MM:SSZ (or similar) format, as is the result of serializing the model with serde_json::json!().

Actual Behavior

The resulting JsonValue has the correct structure, but any date or datetime fields are missing.

Reproduces How Often

Every time.

Versions

├── sea-orm v0.6.0
│ ├── sea-orm-macros v0.6.0 (proc-macro)
│ ├── sea-query v0.21.0
│ │ ├── sea-query-derive v0.2.0 (proc-macro)
│ ├── sea-strum v0.23.0
│ │ └── sea-strum_macros v0.23.0 (proc-macro)

│ ├── sqlx v0.5.10
│ │ ├── sqlx-core v0.5.10
│ │ │ ├── sqlformat v0.1.8
│ │ │ ├── sqlx-rt v0.5.10
│ │ └── sqlx-macros v0.5.10 (proc-macro)
│ │ ├── sqlx-core v0.5.10 (*)
│ │ ├── sqlx-rt v0.5.10 (*)

I'm using MySQL 8.0 on Windows 10.

Additional Information

Relevant lines from Cargo.toml (remaining crates are actix dependencies and other unrelated items):

chrono = { version = "^0.4", features = ["serde"] }
serde = "^1.0"
serde_json = "^1.0"

[dependencies.sea-orm]
version = "^0.6.0"
default-features = false
features = ["macros", "runtime-actix-native-tls", "debug-print", "with-json", "with-chrono"]

[features]
default = ["sqlx-mysql"]
sqlx-mysql = ["sea-orm/sqlx-mysql"]

Here is a minimal repository showing the issue.

@billy1624
Copy link
Member

Hey @e-rhodes, sorry for the delay. Thanks for providing a minimal reproducible example! Please check #539 for the fix.

@billy1624 billy1624 self-assigned this Feb 17, 2022
@junbl
Copy link
Contributor Author

junbl commented Mar 11, 2022

Been using this branch with no issues---nice work! Will it be merged into master sometime soon or is this waiting for a 0.7 release?

@yashsamit
Copy link

Please merge. It's a blocker. Also, UUID is not converting when using into_json.

This is a wonderful library and works very well with some patience. I think adding more examples in documentation will make it easier to use.

@billy1624
Copy link
Member

Been using this branch with no issues---nice work! Will it be merged into master sometime soon or is this waiting for a 0.7 release?

We will release it on 0.7 once we got the UUID covered in into_json method.

@billy1624
Copy link
Member

This is a wonderful library and works very well with some patience. I think adding more examples in documentation will make it easier to use.

Hey @yashsamit, thanks for the support! Do you have any suggestions on what to add? In terms of examples and documentations?

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.

3 participants