mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +00:00
fix: implement transparent Serialize and Deserialize for Json<_>
This commit is contained in:
parent
93728a051c
commit
e7e2f5b37a
@ -1,5 +1,6 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json::value::RawValue as JsonRawValue;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
@ -9,7 +10,8 @@ use crate::encode::{Encode, IsNull};
|
||||
use crate::error::BoxDynError;
|
||||
use crate::types::Type;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Json<T>(pub T);
|
||||
|
||||
impl<T> Deref for Json<T> {
|
||||
|
@ -142,6 +142,9 @@ mod json_tests {
|
||||
"\'{\"name\":\"Joe\",\"age\":33}\'" == Json(Friend { name: "Joe".to_string(), age: 33 })
|
||||
));
|
||||
|
||||
// NOTE: This is testing recursive (and transparent) usage of the `Json` wrapper. You don't
|
||||
// need to wrap the Vec in Json<_> to make the example work.
|
||||
|
||||
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, sqlx::FromRow)]
|
||||
struct Customer {
|
||||
json_column: Json<Vec<i64>>,
|
||||
@ -149,6 +152,6 @@ mod json_tests {
|
||||
|
||||
test_type!(json_struct_json_column<Json<Customer>>(
|
||||
MySql,
|
||||
"\'{ \"json_column\": [1, 2] }\'" == Json(Customer { json_column: Json(vec![1, 2]) })
|
||||
"\'{\"json_column\":[1,2]}\'" == Json(Customer { json_column: Json(vec![1, 2]) })
|
||||
));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user