Repository navigation
Closed
Description
See
Lines 6446 to 6482 in d6a1e4f
| #[test] | |
| fn avro_rs_53_uuid_with_fixed() -> TestResult { | |
| #[derive(Debug, Serialize, Deserialize)] | |
| struct Comment { | |
| id: crate::Uuid, | |
| } | |
| impl AvroSchema for Comment { | |
| fn get_schema() -> Schema { | |
| Schema::parse_str( | |
| r#"{ | |
| "type" : "record", | |
| "name" : "Comment", | |
| "fields" : [ { | |
| "name" : "id", | |
| "type" : { | |
| "type" : "fixed", | |
| "size" : 16, | |
| "logicalType" : "uuid", | |
| "name": "FixedUUID" | |
| } | |
| } ] | |
| }"#, | |
| ) | |
| .expect("Invalid Comment Avro schema") | |
| } | |
| } | |
| let payload = Comment { | |
| id: "de2df598-9948-4988-b00a-a41c0e287398".parse()?, | |
| }; | |
| let mut buffer = Vec::new(); | |
| SpecificSingleObjectWriter::<Comment>::with_capacity(10)? | |
| .write_ref(&payload, &mut buffer)?; | |
| Ok(()) | |
| } |
Here the test uses
SpecificSingleObjectWriter::<Comment>::with_capacity(10)?
.write_ref(&Comment {id: "de2df598-9948-4988-b00a-a41c0e287398".parse()?}, &mut buffer)?;
The Avro Schema is available via Comment::get_schema() but it is not used at
Lines 551 to 555 in d6a1e4f
| pub fn write_ref<W: Write>(&mut self, data: &T, writer: &mut W) -> AvroResult<usize> { | |
| let mut serializer = Serializer::default(); | |
| let v = data.serialize(&mut serializer)?; | |
| self.inner.write_value_ref(&v, writer) | |
| } |
Serde does not work with schemas.
We need to find a way to make use of the schema because now the id struct field is serialized/encoded as a types::Value::String instead of Uuid or even Fixed(16), as defined in the schema.
Metadata
Metadata
Assignees
Labels
No labels
Activity
jdarais commentedon Mar 2, 2025
Hi, thanks for your great work on this library. I started playing around with avro/rust, and ended up creating a PR (#139) that proposes some improvements, which would fix this issue as well. I think the crux of the matter is that the schema isn't being used by the serializer. You're right that
Serdedoesn't work with schemas, and no schema information embedded in the type being serialized would be exposed to the serializer, but you can implement aSerializerthat contains a schema to reference when serializing any value. That's the approach that my PR takes, though you could likely do the same with aSerializerthat serializes to a aValue.Schema-aware serializer for "Serde Way" (apache#139)