-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to ignore double quotation mark when do serialization? #362
Comments
That is impossible now. In my fork, https://github.com/Mingun/fast-xml, I'll plan to implement API for set desired level of quoting: enum QuoteLevel {
/// - `<` -> `<`
/// - `>` -> `>`
/// - `&` -> `&`
/// - `"` -> `"`
/// - `'` -> `'`
Full,
/// - `<` -> `<`
/// - `>` -> `>`
/// - `&` -> `&`
Partial,
/// - `<` -> `<`
/// - `&` -> `&`
Minimal,
}
let mut s = Serializer::new(...);
s.set_quote_level(QuoteLevel::Minimal);
... |
This requires a bit more work than I expect initially. I think, it is needed to split
|
This is currently possible to do with the raw, non-serde API. use quick_xml::{Writer, events::Event, events::BytesDecl, events::BytesText, events::BytesStart, escape::partial_escape};
use std::fs::File;
use std::io::Cursor;
use std::io::Write;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut writer = Writer::new_with_indent(Cursor::new(Vec::new()), b' ', 2);
writer.create_element("test")
.write_text_content(BytesText::from_escaped(partial_escape(r#""349DC700140D7F86A0784842780****""#.as_bytes())))?;
print!("{}", std::str::from_utf8(&writer.into_inner().into_inner())?);
Ok(())
}
https://docs.rs/quick-xml/latest/quick_xml/escape/fn.partial_escape.html |
Also this issue seems like a duplicate of #350 |
Yeah, initially I thought, that I probably could provide a function for |
Any updates on this? I met the same problem here (Yes, aws s3 again). I tried to use #[derive(Default, Debug, Serialize)]
#[serde(default, rename_all = "PascalCase")]
struct CompleteMultipartUploadRequestPart {
#[serde(rename = "$unflatten=PartNumber")]
part_number: usize,
#[serde(rename = "$unflatten=ETag", serialize_with = "partial_escape")]
etag: String,
}
fn partial_escape<S>(s: &str, ser: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
ser.serialize_str(&String::from_utf8_lossy(
&quick_xml::escape::partial_escape(s.as_bytes()),
))
}
|
As a quick fix I could suggest to change quick-xml locally and build with the patched version. You should make changes here: Lines 98 to 111 in be8138f
- BytesText::new(&value)
+ BytesText::from_escaped(&crate::escape::partial_escape(&value)) Or you could implement a |
I should say, that quick fix, suggested above, will not work correctly in all cases. This code writes also attribute values and avoiding escape |
Before serialization:
r#""349DC700140D7F86A0784842780****""
After serialization:
However, What expect:
"349DC700140D7F86A0784842780****"
How to ignore serializing double quotation mark?
The text was updated successfully, but these errors were encountered: