I'm serializing a struct to JSON by passing it to Rouille's Response::json()
method, which calls
let data = serde_json::to_string(content).unwrap();
on it. I don't have control over this line, as it comes from the Rouille crate.
In my struct I have a Vec<u8>
(containing a JPEG image):
pub struct Status {
name: String,
#[serde(skip_deserializing)]
pub map: Option<Vec<u8>>,
}
By default the struct is encoded as {"name": "Foo", "map": [255, 216, 255, 224, 0, ...]}
.
This is a bit problematic to deal with in my client application, so I'd like to encode it as base64, a relatively common standard when packing binary data into a JSON.
I tried the crate serde_bytes like this:
pub struct Status {
name: String,
#[serde(skip_deserializing, with="serde_bytes")]
pub map: Vec<u8>,
}
but that seems to be doing nothing. (I removed the Option
just in case that causes the issue.)
I guess I'm looking for something like #[serde(with="base64")]
? Is there a crate that provides it?