Skip to content

Unable to (de)serialize nested JSON Blobs using serde Traits #676

@mara-schulke

Description

@mara-schulke

Description

We have a database schema where we save (from the db pov) untyped json blobs into the database + some metadata columns. We have a serde compatible struct for describing the blobs on the rust side and expected to be able to use the #[sea_orm(db_type = "Json")] as annotation to be able to deserialize the JSON col into the rust struct on select.

Steps to Reproduce

Rust

use some_external_crate::priding::our::type::SomeStruct;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "table_name")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: String,
    #[sea_orm(db_type = "Json")]
    pub details: SomeStruct,
    pub refreshed_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

...

SQL

CREATE TABLE table_name (
    id varchar(64) PRIMARY KEY,
    refreshed_at   timestamptz NOT NULL,
    details        jsonb NOT NULL
);

Expected Behavior

The details field of the Model should be deserialized from json / jsonb columns into the SomeStruct type in rust.

Actual Behavior

"the trait bound `sea_orm::Value: From<SomeStruct>` is not satisfied"

Reproduces How Often

Every time.

Versions

0.7.1

Additional Information

None

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions