Failed to reconstruct schema with avrov2
when Serialize()
a struct containing interface{}
fields
#1372
Open
1 of 7 tasks
Description
hamba/avro
provides a codegen toolavrogen
to generate a Go struct from an avro schema, and I'm using it to migrate some code away from v1 avro. However, for some unions,avrogen
produce fields withany
(interface{}
) type, andavrov2.Serialize()
doesn't handle those fields (withoutUseSchemaID
,UseLatestVersion
, orUseLatestWithMetadata
).Specifically, in the following section, the serializer tries to use
StructToSchema
to reconstruct the avro representation of the Go struct and use it to search on Schema Registry for a schema ID:confluent-kafka-go/schemaregistry/serde/avrov2/avro.go
Lines 95 to 109 in bf51d32
But
StructToSchema
can't infer the exact type of aninterface{}
field, which generates byavrogen
, and errors out:StructToSchema: unknown type interface
.On the other hand, even if it works, I still have doubts if it can actually reconstruct a schema the is logically equivalent to the original one. For example, if the original schema of a field looks like this
By
avrogen
, it becomesIn this case, I couldn't think of a reasonable way for
StructToSchema
to figure out that the field migh contain more than one type, and this could cause the schema registry client fail to search in the registry?For now I'm using fixed schema ID configured with the serializer to circumvent this piece of code, but it's pretty inflexible, and definitely defeats the purpose of having a schema registry for producers.
Maybe a similar approach like (v1) avro specific serializer below, allowing passing a canned schema string on a struct to the schema registry client, can be reintroduced?
confluent-kafka-go/schemaregistry/serde/avro/avro_specific.go
Lines 68 to 77 in bf51d32
avrogen
also has an option-encoders
to put schemas and some helpers on generated structs.How to reproduce
Checklist
Please provide the following information:
LibraryVersion()
): v2.6.1 / v2.6.1ConfigMap{...}
"debug": ".."
as necessary)The text was updated successfully, but these errors were encountered: