Hi,
When working with a union of records, I am unable to deserialize record using apache_avro.
Example schema Foo.avsc:
{
"type": "record",
"name": "Foo",
"fields": [
{"name": "a", "type": "int"},
{"name": "b",
"type":
[
{
"type": "record",
"name": "Bar",
"fields": [
{"name": "c", "type": "long"}
]
},
{
"type": "record",
"name": "Baz",
"fields": [
{"name": "d", "type": "int"}
]
}
]
}
]
}
Expecting struct to be identical when serialized, and then deserialized:
#[test]
fn test_foo_serde() {
let before = Foo {
a: 0,
b: UnionBarBaz::Baz(Baz {
d: 42,
})
};
let schema = Schema::parse_str(include_str!("../avsc/Foo.avsc")).unwrap();
let mut writer = Writer::new(&schema, Vec::new());
writer.append_ser(before.clone()).unwrap();
let encoded = writer.into_inner().unwrap();
let mut reader = Reader::with_schema(&schema, &encoded[..]).unwrap();
let value = reader.next().unwrap();
let after: Foo = from_value::<Foo>(&value.unwrap()).unwrap();
assert_eq!(before, after);
}
The call to from_value() is responding with the following error:
Failed to deserialize Avro value into value: Expected a Record|Enum, but got Union(1, Record([("d", Int(42))]))
Hi,
When working with a union of records, I am unable to deserialize record using apache_avro.
Example schema
Foo.avsc:{ "type": "record", "name": "Foo", "fields": [ {"name": "a", "type": "int"}, {"name": "b", "type": [ { "type": "record", "name": "Bar", "fields": [ {"name": "c", "type": "long"} ] }, { "type": "record", "name": "Baz", "fields": [ {"name": "d", "type": "int"} ] } ] } ] }Expecting struct to be identical when serialized, and then deserialized:
The call to
from_value()is responding with the following error: