Theodlz commented on issue #435:
URL: https://github.com/apache/avro-rs/issues/435#issuecomment-3795679773
HOWEVER, here is another bug that's probably related, and much easier to
reproduce:
```rust
use apache_avro::{AvroSchema, Writer};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, AvroSchema)]
pub enum Color { G, R, I }
#[derive(Deserialize, Serialize, AvroSchema)]
pub struct A {
pub time: f64,
pub color: Option<Color>,
}
fn main() {
let test = A {
time: 123.0,
color: Some(Color::R),
};
let schema = A::get_schema();
let mut writer = Writer::with_codec(
&schema,
Vec::new(),
apache_avro::Codec::Snappy,
)
.unwrap();
writer.append_ser(test).unwrap();
}
```
Here, it shows that it can't generate a proper Avro definition for an option
of an enum (`Option<Color>` in this example), as it fails with the error:
```rust
Error { details: Failed to serialize field 'color' for record
Record(RecordSchema { name: Name { name: "A", namespace: None }, aliases: None,
doc: None, fields: [RecordField { name: "time", doc: None, aliases: None,
default: None, schema: Double, order: Ascending, position: 0,
custom_attributes: {} }, RecordField { name: "color", doc: None, aliases: None,
default: None, schema: Union(UnionSchema { schemas: [Null, Enum(EnumSchema {
name: Name { name: "Color", namespace: None }, aliases: None, doc: None,
symbols: ["G", "R", "I"], default: None, attributes: {} })], variant_index:
{Null: 0, Enum: 1} }), order: Ascending, position: 1, custom_attributes: {} }],
lookup: {"color": 1, "time": 0}, attributes: {} }): Failed to serialize value
of type unit struct using schema Enum(EnumSchema { name: Name { name: "Color",
namespace: None }, aliases: None, doc: None, symbols: ["G", "R", "I"], default:
None, attributes: {} }): Color. Cause: Expected Null or Union schema. Got: Enum
}
```
So here, it clearly mixes up optional and non optional field
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]