Skip to content

Marshaling and unmarshaling turns empty slice into nil #111

@bryantwr

Description

@bryantwr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions