diff options
Diffstat (limited to 'vendor/derive_builder/tests/forward_serde_attrs.rs')
-rw-r--r-- | vendor/derive_builder/tests/forward_serde_attrs.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/derive_builder/tests/forward_serde_attrs.rs b/vendor/derive_builder/tests/forward_serde_attrs.rs new file mode 100644 index 000000000..2ba7bcf80 --- /dev/null +++ b/vendor/derive_builder/tests/forward_serde_attrs.rs @@ -0,0 +1,29 @@ +#[macro_use] +extern crate derive_builder; +extern crate serde; +extern crate serde_json; + +#[derive(Builder)] +#[builder(setter(into), derive(serde::Serialize))] +#[builder_struct_attr(serde(rename_all = "camelCase"))] +#[allow(dead_code)] +struct Example { + first_name: String, + middle_name: String, + #[builder_field_attr(serde(rename = "familyName"))] + last_name: String, +} + +#[test] +fn serialize_builder() { + assert_eq!( + serde_json::to_string( + &ExampleBuilder::default() + .first_name("Jane") + .middle_name("Alice") + .last_name("Doe"), + ) + .unwrap(), + r#"{"firstName":"Jane","middleName":"Alice","familyName":"Doe"}"# + ); +} |