diff --git a/derive/src/serde_json.rs b/derive/src/serde_json.rs index ba2ad83..51aa91c 100644 --- a/derive/src/serde_json.rs +++ b/derive/src/serde_json.rs @@ -249,8 +249,8 @@ pub fn derive_de_json_proxy(proxy_type: &str, type_: &str) -> TokenStream { format!( "impl DeJson for {} {{ #[allow(clippy::ignored_unit_patterns)] - fn de_json(_s: &mut nanoserde::DeJsonState, i: &mut core::str::Chars) -> ::core::result::Result {{ - let proxy: {} = DeJson::deserialize_json(i)?; + fn de_json(s: &mut nanoserde::DeJsonState, i: &mut core::str::Chars) -> ::core::result::Result {{ + let proxy: {} = DeJson::de_json(s, i)?; ::core::result::Result::Ok(Into::into(&proxy)) }} }}", diff --git a/tests/json.rs b/tests/json.rs index 0f11100..d143727 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -908,6 +908,42 @@ fn field_proxy() { assert!(test == test_deserialized); } +#[test] +fn object_proxy() { + #[derive(DeJson, SerJson, PartialEq, Debug)] + #[nserde(proxy = "Serializable")] + pub struct NonSerializable { + foo: i32, + } + + #[derive(DeJson, SerJson, PartialEq, Debug)] + pub struct Serializable { + x: i32, + } + + impl From<&NonSerializable> for Serializable { + fn from(non_serializable: &NonSerializable) -> Serializable { + Serializable { + x: non_serializable.foo, + } + } + } + impl From<&Serializable> for NonSerializable { + fn from(serializable: &Serializable) -> NonSerializable { + NonSerializable { + foo: serializable.x, + } + } + } + + let test = NonSerializable { foo: 6 }; + + let bytes = SerJson::serialize_json(&test); + let test_deserialized = DeJson::deserialize_json(&bytes).unwrap(); + + assert!(test == test_deserialized); +} + #[test] fn field_option_proxy() { #[derive(PartialEq, Clone, Debug)]