From cb2b92f828c48edf714350815ffa984b8aa4ad31 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 1 May 2018 22:25:06 -0700 Subject: [PATCH] Handle flatten + deserialize_with --- serde_derive/src/de.rs | 6 +++++- test_suite/tests/test_gen.rs | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index e08a1fcf..af3d3693 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -2279,8 +2279,12 @@ fn deserialize_map( .filter(|&&(field, _)| field.attrs.flatten()) .map(|&(field, ref name)| { let field_ty = field.ty; + let func = match field.attrs.deserialize_with() { + None => quote!(_serde::de::Deserialize::deserialize), + Some(path) => quote!(#path), + }; quote! { - let #name: #field_ty = try!(_serde::de::Deserialize::deserialize( + let #name: #field_ty = try!(#func( _serde::private::de::FlatMapDeserializer( &mut __collect, _serde::export::PhantomData))); diff --git a/test_suite/tests/test_gen.rs b/test_suite/tests/test_gen.rs index 2a78fcf7..e06ec5a8 100644 --- a/test_suite/tests/test_gen.rs +++ b/test_suite/tests/test_gen.rs @@ -492,6 +492,13 @@ fn test_gen() { } assert_ser::(); + #[derive(Serialize, Deserialize)] + struct FlattenWith { + #[serde(flatten, serialize_with = "ser_x", deserialize_with = "de_x")] + x: X, + } + assert::(); + #[derive(Serialize, Deserialize)] struct StaticStrStruct<'a> { a: &'a str,