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::http::Status;
|
||||
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
|
||||
use serde_json;
|
||||
|
||||
pub use serde_json::error::Error as SerdeError;
|
||||
|
@ -186,6 +185,18 @@ impl<T> DerefMut for Json<T> {
|
|||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
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 {
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> serde_json::Value {
|
||||
|
|
Loading…
Reference in New Issue