Interpretting Uuid produces SerdeError
Closed this issue · 1 comments
piropaolo27 commented
Hi, I'm trying to use avro_rs
to deserialize data into a struct with a Uuid
field, but to no avail. Please give me advice how to get this one right. Here's a MRE
:
use avro_rs::types::Value;
use serde::Deserialize;
use uuid::Uuid;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
pub event_uuid: Uuid,
}
fn main() {
let uuid = Value::Uuid(Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap());
let metadata = Value::Record(vec![
("eventUuid".to_owned(), uuid),
]);
let avro_metadata = avro_rs::from_value::<Metadata>(&metadata);
eprintln!("metadata_avro = {:#?}", metadata_avro);
}
Cargo.toml
[package]
name = "pp-avro"
version = "0.1.0"
edition = "2018"
[dependencies]
avro-rs = { version = ">= 0.6" }
serde = "1.0"
serde_json = "1.0"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
It gives me the error:
metadata_avro = Err(
Error {
message: "not a string|bytes|fixed",
},
)
On the other hand, that one is working perfectly fine:
fn main() {
let uuid = Value::String("b4b3f490-d8cc-46fe-8d52-a395d7fb209f".to_owned());
let metadata = Value::Record(vec![
("eventUuid".to_owned(), uuid),
]);
let avro_metadata = avro_rs::from_value::<Metadata>(&metadata);
eprintln!("metadata_avro = {:#?}", metadata_avro);
}
piropaolo27 commented
Here's link to my PR
: #153