Permalink
Browse files

Fix omitempty support for floats.

  • Loading branch information...
1 parent c1cd225 commit 7ad95dd0798a40da1ccdff6dff35fd177b5edf40 @niemeyer niemeyer committed Jun 24, 2015
Showing with 10 additions and 2 deletions.
  1. +7 −1 encode_test.go
  2. +3 −1 yaml.go
View
@@ -190,6 +190,12 @@ var marshalTests = []struct {
A struct{ X, y int } "a,omitempty,flow"
}{struct{ X, y int }{0, 1}},
"{}\n",
+ }, {
+ &struct {
+ A float64 "a,omitempty"
+ B float64 "b,omitempty"
+ }{1, 0},
+ "a: 1\n",
},
// Flow flag
@@ -340,7 +346,7 @@ var marshalErrorTests = []struct {
panic: `Duplicated key 'b' in struct struct \{ B int; .*`,
}, {
value: &struct {
- A int
+ A int
B map[string]int ",inline"
}{1, map[string]int{"a": 2}},
panic: `Can't have key "a" in inlined map; conflicts with struct field`,
View
@@ -324,13 +324,15 @@ func isZero(v reflect.Value) bool {
return v.Len() == 0
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int() == 0
+ case reflect.Float32, reflect.Float64:
+ return v.Float() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return v.Uint() == 0
case reflect.Bool:
return !v.Bool()
case reflect.Struct:
vt := v.Type()
- for i := v.NumField()-1; i >= 0; i-- {
+ for i := v.NumField() - 1; i >= 0; i-- {
if vt.Field(i).PkgPath != "" {
continue // Private field
}

1 comment on commit 7ad95dd

@gyuho
gyuho commented on 7ad95dd Jun 25, 2015

Thanks!

Please sign in to comment.