Skip to content

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

@junbl

Description

@junbl

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions