Inability to specify custom namespace for java-key-class entries when using @AvroNamespace annotation in those classes (original) (raw)

Hey, so when generating a avro schema using the AvroMapper and AvroSchemaGenerator, thanks to #310 we can specify the custom namespace each class should have. Now, given a class

ExampleClass.java

package com.example.test

import com.fasterxml.jackson.dataformat.avro.annotation.AvroNamespace;

import java.util.Map;

@AvroNamespace("com.github.test") public class ExampleClass {

public Map<ExampleEnum, String> exampleMap;

}

and the enum

ExampleEnum.java

package com.example.test

import com.fasterxml.jackson.dataformat.avro.annotation.AvroNamespace;

@AvroNamespace("com.github.test") public enum ExampleEnum { FOO, BAR }

, generating the schema by calling both classes explicitely (since nested generation doesn't work here) will yield

ExampleClass.avsc

{ "type" : "record", "name" : "ExampleClass", "namespace" : "com.github.test", "fields" : [ { "name" : "exampleMap", "type" : [ "null", { "type" : "map", "values" : "string", "java-key-class" : "com.example.test" } ] } ] }

and

ExampleEnum.avsc

{ "type" : "enum", "name" : "ExampleEnum", "namespace" : "com.github.test", "symbols" : [ "FOO", "BAR" ] }

Notice how the specified java-key-class has the wrong namespace defined, since it is simply resolving the package name of the existing Java object.
The likely correct way would be to fetch the contents of the @AvroNamespace annotation inside the enum class and resolve it that way when a java-key-class entry is generated, if possible, and otherwise resolve it the old way.
Because I'm not sure of that possiblity though, another suggestion would be to implement an @AvroKeyClass annotation to be able to manually override that package definition.