[
https://issues.apache.org/jira/browse/AVRO-2805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17086921#comment-17086921
]
Pedro Cardoso Silva commented on AVRO-2805:
-------------------------------------------
I can not reproduce the issue now :D
For curiosity, this is the full test code (the only difference to my original
case was that the enum and class being serialized are in separate files):
{code:java}
import io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import io.confluent.kafka.serializers.KafkaAvroDeserializer
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig
import io.confluent.kafka.serializers.KafkaAvroSerializer
import org.apache.avro.reflect.ReflectData
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.HashMap
class ReflectionAvroSerDeTest {
private val schemaRegistry: SchemaRegistryClient =
MockSchemaRegistryClient()
private val reflectionAvroDeserializer: KafkaAvroDeserializer
private val reflectionAvroSerializer: KafkaAvroSerializer
private val topic = "test";
init {
val reflectionProps = HashMap<String, String>()
// Intentionally invalid schema registry URL to satisfy the config
class's requirement that
// it be set.
// Intentionally invalid schema registry URL to satisfy the config
class's requirement that
// it be set.
reflectionProps[KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG]
= "bogus"
reflectionProps[KafkaAvroDeserializerConfig.SCHEMA_REFLECTION_CONFIG] =
"true"
reflectionAvroSerializer = KafkaAvroSerializer(schemaRegistry,
reflectionProps)
reflectionAvroDeserializer = KafkaAvroDeserializer(schemaRegistry,
reflectionProps)
}
@Test
fun definitionTest() {
val definition = Definition(mapOf("a" to Type.A))
val avroSchema = ReflectData.get().getSchema(Definition::class.java)
val bytes = reflectionAvroSerializer.serialize(topic, definition)
val obj = reflectionAvroDeserializer.deserialize(topic, bytes,
avroSchema)
assertEquals(
Definition::class.java,
obj.javaClass,
"Returned object should be a Definition type"
)
assertEquals(definition, obj)
}
class Definition(val tokens: Map<String, Type> = mapOf()) {
}
enum class Type {
A, B, C
}
}
{code}
I am now wondering whether the original issue was not related to Avro but to
Kafka's Avro Serialization logic.
Either way, thank you for your time, Andy.
Have a great weekend.
> Reflection-based schema not loading types
> ------------------------------------------
>
> Key: AVRO-2805
> URL: https://issues.apache.org/jira/browse/AVRO-2805
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.9.1
> Reporter: Pedro Cardoso Silva
> Priority: Critical
>
> Avro reflection is unable to generate a schema for the following definition:
> {code:java}
> public class Definition {
> public Map<String, Type>
> }
> public enum Type {
> A,
> B,
> C
> }
> {code}
> {code:java}
> // Test code
> Schema schema = ReflectData.get().getSchema(Definition.class)
> {code}
> Fails with:
> Undefined name: "FieldType"
> org.apache.avro.SchemaParseException: Undefined name: "Type"
--
This message was sent by Atlassian Jira
(v8.3.4#803005)