Struct serde_with::json::JsonString
source · [−]pub struct JsonString;
Available on crate feature
json
only.Expand description
Serialize value as string containing JSON
The same functionality is also available as serde_with::json::nested
compatible with serde’s with-annotation.
Examples
#[serde_as]
#[derive(Deserialize, Serialize)]
struct A {
#[serde_as(as = "JsonString")]
other_struct: B,
}
#[derive(Deserialize, Serialize)]
struct B {
value: usize,
}
let v: A = serde_json::from_str(r#"{"other_struct":"{\"value\":5}"}"#).unwrap();
assert_eq!(5, v.other_struct.value);
let x = A {
other_struct: B { value: 10 },
};
assert_eq!(
r#"{"other_struct":"{\"value\":10}"}"#,
serde_json::to_string(&x).unwrap()
);
Trait Implementations
sourceimpl Clone for JsonString
impl Clone for JsonString
sourcefn clone(&self) -> JsonString
fn clone(&self) -> JsonString
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for JsonString
impl Debug for JsonString
sourceimpl Default for JsonString
impl Default for JsonString
sourcefn default() -> JsonString
fn default() -> JsonString
Returns the “default value” for a type. Read more
sourceimpl<'de, T> DeserializeAs<'de, T> for JsonString where
T: DeserializeOwned,
impl<'de, T> DeserializeAs<'de, T> for JsonString where
T: DeserializeOwned,
sourcefn deserialize_as<D>(deserializer: D) -> Result<T, D::Error> where
D: Deserializer<'de>,
fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer.
sourceimpl<T> SerializeAs<T> for JsonString where
T: Serialize,
impl<T> SerializeAs<T> for JsonString where
T: Serialize,
sourcefn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
fn serialize_as<S>(source: &T, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
Serialize this value into the given Serde serializer.
impl Copy for JsonString
Auto Trait Implementations
impl RefUnwindSafe for JsonString
impl Send for JsonString
impl Sync for JsonString
impl Unpin for JsonString
impl UnwindSafe for JsonString
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more