Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported for Avro union #476

Open
attilasuranyi opened this issue Nov 4, 2024 · 1 comment
Open

Unsupported for Avro union #476

attilasuranyi opened this issue Nov 4, 2024 · 1 comment

Comments

@attilasuranyi
Copy link

Is there a way to use schemas with union types like the one below?
With these union fields we are getting errors like "msg:"Id: avro: int is unsupported for Avro union"", and the only workaround I've found so far is defining our struct fields as pointer types, but that is error prone due to nil pointer dereference.

t.Run("Schema union type field", func(t *testing.T) {
    type TestRecord struct {
	    Id int `avro:"id"`
    }
    
    schema, err := avro.Parse(`{
	    "type":"record",
	    "name":"TestRecord",
	    "namespace":"namespace",
	    "fields":[
		    {"name":"id","type":["null","int"]}
	    ]}`)
    assert.Nil(t, err)
    
    in := TestRecord{Id: 5}
    recordBinary, err := avro.Marshal(schema, in)
    assert.Nil(t, err)
    
    out := TestRecord{}
    err = avro.Unmarshal(schema, recordBinary, &out)
    assert.Nil(t, err)
})
@nrwiersma
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants