Skip to content

Commit

Permalink
Merge branch 'pr/54'
Browse files Browse the repository at this point in the history
Change-Id: Ia84202bfb382bfa4717d0b7626c73d9f1e3986ec
  • Loading branch information
skriptble committed May 17, 2018
2 parents 60a04ea + 8daafec commit 29a4d7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bson/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ func (e *encoder) encodeStruct(val reflect.Value) ([]*Element, error) {

field := val.Field(i)

if omitempty && e.isZero(field) {
continue
}

switch t := field.Interface().(type) {
case *Element:
elems = append(elems, t)
Expand Down Expand Up @@ -522,10 +526,6 @@ func (e *encoder) encodeStruct(val reflect.Value) ([]*Element, error) {
}
field = e.underlyingVal(field)

if omitempty && e.isZero(field) {
continue
}

if inline {
switch sf.Type.Kind() {
case reflect.Map:
Expand Down
10 changes: 10 additions & 0 deletions bson/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,16 @@ func reflectionEncoderTest(t *testing.T) {
docToBytes(NewDocument()),
nil,
},
{
"omitempty, empty time",
struct {
A time.Time `bson:",omitempty"`
}{
A: time.Time{},
},
docToBytes(NewDocument()),
nil,
},
{
"no private fields",
struct {
Expand Down

0 comments on commit 29a4d7d

Please sign in to comment.