Reputation: 81
I would like to use auto-generated java classes from an avro schema to consume kafka messages. Unfortunately the avro schema has no namespace defined (and the owner of the schema is a little hesistant to add one).
If I generate the classes using the avro maven plugin they end up in the root package. So it seems that I can not import and use them in my java classes.
So the question is how to handle avro schemas without namespace?
I had the following ideas:
Error-Message I get when trying case 2 (namespace added by myself):
org.apache.kafka.common.errors.SerializationException: Could not find class MyClass specified in writer's schema whilst finding reader's schema for a SpecificRecord.
Upvotes: 0
Views: 2523
Reputation: 191681
The workaround in the issue is to read the raw AVSC file as JSON and add a namespace to the record if one doesn't exist, which is what you already proposed.
Without doing something like that, as you've discovered, then you'll be unable to import any generated class in your Java project.
Regarding Kafka, it's not clear what deserializer you're using. If using Confluent's, you may need to define your own that doesn't lookup the writer schema in the schema registry.
Reminder - you can always use GenericRecord types instead.
Upvotes: 1