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

Marshaling and unmarshaling turns empty slice into nil #111

Open
bryantwr opened this issue Jul 1, 2022 · 1 comment
Open

Marshaling and unmarshaling turns empty slice into nil #111

bryantwr opened this issue Jul 1, 2022 · 1 comment

Comments

@bryantwr
Copy link

bryantwr commented Jul 1, 2022

Hi there!

I'm finding that using marshal and unmarshal on an empty slice in a struct turns that value into a nil, which seems incorrect, given that I believe the Avro spec supports empty values. e.g.

func TestAvroEmpty(t *testing.T) {
	a := assert.New(t)
	type A struct {
		EmptySlice []string
	}
	mockA := A{
		EmptySlice: []string{},
	}
	marshalA, schemaA, err := avro.Marshal(mockA)
	a.Nil(err)

	var newA A
	_, err = avro.Unmarshal(marshalA, &newA, schemaA)
	a.Nil(err)

	diff := cmp.Diff(mockA, newA)
	a.Empty(diff)
}

yields the output:

=== RUN   TestA
...
        	Error:      	Should be empty, but was A{
        	            	- 	EmptySlice: []string{},
        	            	+ 	EmptySlice: nil,
        	            	  }
        	Test:       	TestA
--- FAIL: TestA (0.00s)

Is this expected behavior for the library?

@skateinmars
Copy link
Member

Hey @bryantwr ,
this does look like an issue, especially since in that case the array is not optional

From what I understand from the Avro specs nil arrays should only happen when the field is a union of ["null", array] and the value is actually null

We have a limited bandwidth to work on this but feel free to dig into the code and open a PR!

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

No branches or pull requests

2 participants