You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deserializing Panic with UTF-8 BOM (Byte Order Mark) Content
I encounter an issue when attempting to deserialize a string encoded in UTF-8 with a Byte Order Mark (BOM). The deserializer throws the following error: Error("expected value", line: 1, column: 1).
How to Reproduce
To reproduce the issue, encode a JSON file in UTF-8 with BOM and use from_reader or from_str for deserialization.
Workaround
As a temporary workaround, I check if the file content begins with the first three bytes of the BOM and remove them if present:
use std::fs;fnmain(){// Specify the path to your filelet file_path = "path/to/your/file_with_bom.json";// Read the file to a Vec<u8>letmut data = fs::read(file_path).unwrap();// UTF-8 BOM is three bytes: EF BB BFif data.starts_with(&[0xEF,0xBB,0xBF]){// Remove the first three bytes (the BOM)
data = data[3..].to_vec();}// Proceed with deserialization...}
The text was updated successfully, but these errors were encountered:
dtolnay
changed the title
Deserializing Panic with UTF-8 BOM (Byte Order Mark) Content
Deserializing error with UTF-8 BOM (Byte Order Mark) Content
Mar 5, 2024
Deserializing Panic with UTF-8 BOM (Byte Order Mark) Content
I encounter an issue when attempting to deserialize a string encoded in UTF-8 with a Byte Order Mark (BOM). The deserializer throws the following error:
Error("expected value", line: 1, column: 1)
.How to Reproduce
To reproduce the issue, encode a JSON file in UTF-8 with BOM and use
from_reader
orfrom_str
for deserialization.Workaround
As a temporary workaround, I check if the file content begins with the first three bytes of the BOM and remove them if present:
The text was updated successfully, but these errors were encountered: