Open ghost opened 2 years ago
@gavrilyuc2 This is not a bug. Upgrading to linkedin/goavro 2.11 would not fix it. (I tried)
In the Avro schema, the gender type is a union. Union in goavro is actually very well documented at https://github.com/linkedin/goavro#translating-from-avro-to-go-data Here is the exact description how the library is encoding a union
Because of encoding rules for Avro unions, when an union's value is null, a simple Go nil is returned. However when an union's value is non-nil, a Go map[string]interface{} with a single key is returned for the union. The map's single key is the Avro type name and its value is the datum's value.
The means you need to declare the data structure as the following.
type UserPulsarMessage struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Gender map[string]interface{} `json:"gender"`
}
Gender has to be a map according to the README. The value is initialized as
Gender: map[string]interface{}{"string": "male"},
or
Gender: nil,
I hope this helps.
What about this package?
I think it will be right for simple union types because I have a problem with using map[string]interface{}
type with other (python with go producers and consumers) and for producing messages it will be ok, but for consuming messages we have an error like that I wrote before.
But if I use this package I don't see this error.
Example code:
Output: