Open JorritSalverda opened 2 years ago
I have the following struct I'm trying to serialize:
use serde_xml_rs::{from_str, to_string}; use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] #[serde(rename = "request")] pub struct TokenRequest { pub client: String, pub username: String, pub password: String, }
However when I run the following test with an & in a value it should be encoded as &. Unfortunately to_string fails to do so and just keeps &.
&
&
to_string
#[test] fn serialize_access_token_request() { let token_request = TokenRequest { client: "a".to_string(), username: "b".to_string(), password: "c&d".to_string(), }; // act let request = to_string(&token_request).unwrap(); assert_eq!(request, r#"<request><client>a</client><username>b</username><password>c&d</password></request>"#); }
It fails as follows:
---- timewax_client::tests::serialize_access_token_request stdout ---- thread 'timewax_client::tests::serialize_access_token_request' panicked at 'assertion failed: `(left == right)` left: `"<request><client>a</client><username>b</username><password>c&d</password></request>"`, right: `"<request><client>a</client><username>b</username><password>c&d</password></request>"`', src/timewax_client.rs:137:7 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
My Cargo.toml has the following dependencies (and some others that aren't relevant to this issue I would say):
Cargo.toml
[dependencies] serde = "1.0.136" serde-xml-rs = "0.5.1"
Off-topic, shouldn't the serialized string also start with <?xml version="1.0" encoding="utf-8"?>?
<?xml version="1.0" encoding="utf-8"?>
I have the following struct I'm trying to serialize:
However when I run the following test with an
&
in a value it should be encoded as&
. Unfortunatelyto_string
fails to do so and just keeps&
.It fails as follows:
My
Cargo.toml
has the following dependencies (and some others that aren't relevant to this issue I would say):Off-topic, shouldn't the serialized string also start with
<?xml version="1.0" encoding="utf-8"?>
?