Closed
Description
Hello,
I've encountered an issue while trying to serialize a simple struct with union type into avro recrod.
{
"name": "Reference",
"type": "record",
"fields": [
{
"name": "feedReference",
"type": [
"null",
{
"name": "FeedReference",
"type": "record",
"fields": [
{
"name": "instance",
"type": "string"
},
{
"name": "provider",
"type": "string"
}
]
}
],
"default": null
}
]
}
Simple rust code to reproduce the issue:
#[derive(Serialize, Deserialize)]
struct Reference {
#[serde(rename = "feedReference")]
pub feed_reference: Option<FeedReference>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct FeedReference {
pub instance: String,
pub provider: String,
}
impl Default for FeedReference {
fn default() -> FeedReference {
FeedReference {
instance: String::default(),
provider: String::default(),
}
}
}
#[test]
fn validate_schema_avrow() {
let reference = Reference {
feed_reference: Some(FeedReference::default()),
};
let schema_str = std::fs::read_to_string("avro/feed_reference.avsc").unwrap();
let schema = Schema::from_str(&schema_str).unwrap();
let mut writer = Writer::new(&schema, vec![]).unwrap();
writer.serialize(reference).unwrap();
}
And the result:
thread 'test::validate_schema_avrow' panicked at 'called `Result::unwrap()` on an `Err` value: SchemaNotFoundInUnion', crates/platform_content/src/lib.rs:36:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test test::validate_schema_avrow ... FAILED
The funny thing is, that when I pass None
into the feed_reference
field, struct seems to serialize correctly.
The same schema and struct serializes just fine using e.g avro-rs.
Metadata
Metadata
Assignees
Labels
No labels