This repository was archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Byte arrays are represented as strings in generated avro schema? #39
Copy link
Copy link
Closed
Milestone
Description
It looks like byte arrays are represented as strings in the generated Avro schema. When I try to generate a schema from my File class below and use that schema to write an Avro message, I get an JsonMappingException: Not in union ["null",{"type":"array","items":"string"}]: java.nio.HeapByteBuffer[pos=0 lim=9 cap=9]:
private static class File {
public String filename = "TestFile.txt";
public byte[] filedata = "Test Text".getBytes();
}
@Test
public void testAvroSchemaGenerationWithJackson() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper(new AvroFactory());
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
AvroSchemaGenerator visitor = new AvroSchemaGenerator();
mapper.acceptJsonFormatVisitor(File.class, visitor);
AvroSchema schema = visitor.getGeneratedSchema();
ObjectMapper mapper2 = new ObjectMapper(new AvroFactory());
System.out.println(mapper2.writer(schema).writeValueAsBytes(new File()));
}
I believe the reason is, because the generated schema represents the byte array as a string:
{
"type" : "record",
"name" : "File",
"namespace" : "xx.xxx.nss",
"doc" : "Schema for xx.xxx.SchemaGenerationTest$File",
"fields" : [ {
"name" : "filedata",
"type" : [ "null", {
"type" : "array",
"items" : "string"
} ]
}, {
"name" : "filename",
"type" : [ "null", "string" ]
} ]
}
How can I make byte arrays be represented simply by the type "bytes" ? Or is this a bug?
Metadata
Metadata
Assignees
Labels
No labels