diff --git a/encode.go b/encode.go index f05173d..78eb981 100644 --- a/encode.go +++ b/encode.go @@ -218,7 +218,7 @@ func isEmptyValue(v reflect.Value) bool { case reflect.Interface, reflect.Ptr: return v.IsNil() case reflect.Struct: - return v.Interface() == reflect.Zero(v.Type()).Interface() + return reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) } return false } diff --git a/encode_test.go b/encode_test.go index e831c00..ae63c32 100644 --- a/encode_test.go +++ b/encode_test.go @@ -117,6 +117,7 @@ var indentRefOmit = ` type testStruct struct { UnusedString string `plist:"unused-string"` + UnusedByte []byte `plist:"unused-byte,omitempty"` } var encodeTests = []struct { @@ -208,7 +209,7 @@ func TestIndent(t *testing.T) { Size: 4 * 1048576 * 1024 * 1024, DiskImageBundleType: "com.apple.diskimage.sparsebundle", BackingStoreVersion: 1, - Unused: testStruct{"unused"}, + Unused: testStruct{UnusedString: "unused"}, } b, err := MarshalIndent(sparseBundleHeader, " ") if err != nil { @@ -235,7 +236,7 @@ func TestOmitNotEmpty(t *testing.T) { Size: 4 * 1048576 * 1024 * 1024, DiskImageBundleType: "com.apple.diskimage.sparsebundle", BackingStoreVersion: 1, - Unused: testStruct{"unused"}, + Unused: testStruct{UnusedString: "unused"}, } b, err := MarshalIndent(sparseBundleHeader, " ") if err != nil {