FasterXML / FasterXML/jackson-dataformats-binary

Inability to specify custom namespace for `java-key-class` entries when using `@AvroNamespace` annotation in those classes

Abierto
#611 3 comentarios 0 reacciones 0 asignados Ver en GitHub
avro good first issue pr-needed
Lenguaje dominante
Java
Estrellas
347
Forks
156
Merge medio
3 d 3 h
PR fusionados (30 d)
22

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.