FasterXML / FasterXML/jackson-dataformats-binary
Inability to specify custom namespace for `java-key-class` entries when using `@AvroNamespace` annotation in those classes
- Dominant language
- Java
- Stars
- 347
- Forks
- 156
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 22
Description
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
``` 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 exampleMap;
}
```
and the enum
ExampleEnum.java
``` 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
``` 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
``` 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.