Browse Source

merge goyaml-omit-zero-pointers

Roger Peppe 14 years ago
parent
commit
3e69410288
2 changed files with 5 additions and 1 deletions
  1. 4 0
      encode_test.go
  2. 1 1
      goyaml.go

+ 4 - 0
encode_test.go

@@ -76,6 +76,10 @@ var marshalTests = []struct {
 		A int "a,omitempty"
 		B int "b,omitempty"
 	}{0, 0}},
+	{"{}\n", &struct {
+		A *struct{ X int } "a,omitempty"
+		B int              "b,omitempty"
+	}{nil, 0}},
 
 	// Flow flag
 	{"a: [1, 2]\n", &struct {

+ 1 - 1
goyaml.go

@@ -256,7 +256,7 @@ func isZero(v reflect.Value) bool {
 	switch v.Kind() {
 	case reflect.String:
 		return len(v.String()) == 0
-	case reflect.Interface:
+	case reflect.Interface, reflect.Ptr:
 		return v.IsNil()
 	case reflect.Slice:
 		return v.Len() == 0