Skip to content

Logical type UUID with type "fixed" do not serialize to fixed 16 #53

@Tipnos

Description

@Tipnos

Avro 1.12.0 specifies that UUID logical types annotates to either String or Fixed 16.

The example below serialized the UUID to a String and not a Fixed 16

#[derive(Debug, Serialize, Deserialize)]
struct Comment {
    id: 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" // if we remove the name attribute schema parsing fail. The name attribute is not in avro 1.12.0 specification
                  }
                } ]
             }"#,
        )
        .expect("Invalid Comment Avro schema")
    }
}

let payload = Comment {
        id: "de2df598-9948-4988-b00a-a41c0e287398".parse().unwrap(),
};
let mut buffer = Vec::new();
SpecificSingleObjectWriter::<Comment>::with_capacity(10)
    .unwrap()
    .write_ref(&payload, &mut buffer)
    .unwrap();

Do you plan to support it in the near future?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions