Search code examples
javaavro

Generating AVRO classes in specific package


I have two .avsc files with matching namespace and field names. When generating, the classes generated from first schema are being overwritten by classes from the second schema. Is there a way to generate classes in a specific directory, but only for one of the .avsc files?

If I change the namespace in avro schema everything is great, but Kafka messages aren't being read and I get the following error:

Could not find class com.package.TestClaim

Obviously, because avro's namespace after change is com.package.test_claim.TestClaim

This is what's generated when I added *.test_claim to namespace of one of the schemas.

enter image description here


Solution

  • in a specific directory, but only for one of the .avsc files?

    That's what the namespace does. This isn't overridable elsewhere, so yes, two files will conflict if compiled separately.

    Unclear how you are compiling the Java classes, but if you use Avro IDL rather than AVSC, you can declare/combine many record types under a single namespace on the protocol (which will write the classes to a single folder)

    And if you needed different/nested packaging, that is available too

    @namespace("org.apache.avro.firstNamespace")
    protocol MyProto {
      @namespace("org.apache.avro.someOtherNamespace")
      record Foo {}