heetch / heetch/avro

Marshaling and unmarshaling turns empty slice into nil

Open
#111 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
95
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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.

```go
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.