diff --git a/gotype.go b/gotype.go index b43a61c..030d3b0 100644 --- a/gotype.go +++ b/gotype.go @@ -205,7 +205,9 @@ func (gts *goTypeSchema) schemaForGoType(t reflect.Type) (interface{}, error) { if err != nil { return nil, err } - var fields []interface{} + // Note: don't start with nil fields because gogen-avro + // doesn't like the nil value. + fields := []interface{}{} for i := 0; i < t.NumField(); i++ { f := t.Field(i) if f.Anonymous { diff --git a/gotype_test.go b/gotype_test.go index ac02d13..f6850ff 100644 --- a/gotype_test.go +++ b/gotype_test.go @@ -48,6 +48,17 @@ func TestSimpleGoType(t *testing.T) { wg.Wait() } +func TestEmptyGoStructType(t *testing.T) { + c := qt.New(t) + type T struct{} + data, wType, err := avro.Marshal(T{}) + c.Assert(err, qt.Equals, nil) + var x T + _, err = avro.Unmarshal(data, &x, wType) + c.Assert(err, qt.Equals, nil) + c.Check(x, qt.Equals, T{}) +} + func TestGoTypeWithOmittedFields(t *testing.T) { c := qt.New(t) type R struct {