mirror of https://github.com/rwf2/Rocket.git
Implement Serialize + Deserialize for contrib JsonValue.
This commit is contained in:
parent
39c952f8eb
commit
0045486227
|
@ -7,9 +7,8 @@ use rocket::data::{self, Data, FromData};
|
||||||
use rocket::response::{self, Responder, content};
|
use rocket::response::{self, Responder, content};
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::{Serialize, Serializer};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
pub use serde_json::error::Error as SerdeError;
|
pub use serde_json::error::Error as SerdeError;
|
||||||
|
@ -186,6 +185,18 @@ impl<T> DerefMut for Json<T> {
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub struct JsonValue(pub serde_json::Value);
|
pub struct JsonValue(pub serde_json::Value);
|
||||||
|
|
||||||
|
impl Serialize for JsonValue {
|
||||||
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
self.0.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for JsonValue {
|
||||||
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
serde_json::Value::deserialize(deserializer).map(JsonValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl JsonValue {
|
impl JsonValue {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn into_inner(self) -> serde_json::Value {
|
fn into_inner(self) -> serde_json::Value {
|
||||||
|
|
Loading…
Reference in New Issue