Revert "Merge pull request #306 from pjiang-dev/pjiang/fix-remove-items"

This reverts commit 446d8398e19c4b0cedf8b0faadfa75b8fc4f2aca, reversing
changes made to b88846d7771a1e82b60ffdb75f9fecee7d2defb1.
diff --git a/merge/multiple_appliers_test.go b/merge/multiple_appliers_test.go
index 48f54cd..7fad7b1 100644
--- a/merge/multiple_appliers_test.go
+++ b/merge/multiple_appliers_test.go
@@ -1061,14 +1061,14 @@
 				},
 			},
 			Object: `
-			mapOfMapsRecursive:
-			  a: {}
-			  c:
-			    d:
-			      e:
-			        f:
-			          g:
-		`,
+				mapOfMapsRecursive:
+				  a:
+				  c:
+				    d:
+				      e:
+				        f:
+				          g:
+			`,
 			APIVersion: "v1",
 			Managed: fieldpath.ManagedFields{
 				"apply-one": fieldpath.NewVersionedSet(
@@ -1187,13 +1187,13 @@
 				},
 			},
 			Object: `
-			a: {}
-			c:
-			  d:
-			    e:
-			      f:
-			        g:
-		`,
+				a:
+				c:
+				  d:
+				    e:
+				      f:
+				        g:
+			`,
 			APIVersion: "v1",
 			Managed: fieldpath.ManagedFields{
 				"apply-two": fieldpath.NewVersionedSet(
diff --git a/merge/nested_test.go b/merge/nested_test.go
index 2da4d4c..ffdb07b 100644
--- a/merge/nested_test.go
+++ b/merge/nested_test.go
@@ -554,8 +554,8 @@
 				},
 			},
 			Object: `
-			struct: {}
-		`,
+				struct:
+			`,
 			APIVersion: "v1",
 			Managed: fieldpath.ManagedFields{
 				"default": fieldpath.NewVersionedSet(
diff --git a/typed/remove.go b/typed/remove.go
index 0db1734..78ba6f5 100644
--- a/typed/remove.go
+++ b/typed/remove.go
@@ -75,7 +75,6 @@
 	}
 
 	var newItems []interface{}
-	hadMatches := false
 	iter := l.RangeUsing(w.allocator)
 	defer w.allocator.Free(iter)
 	for iter.Next() {
@@ -99,26 +98,12 @@
 				continue
 			}
 			if isPrefixMatch {
-				// Removing nested items within this list item and preserve if it becomes empty
-				hadMatches = true
-				wasMap := item.IsMap()
-				wasList := item.IsList()
 				item = removeItemsWithSchema(item, w.toRemove.WithPrefix(pe), w.schema, t.ElementType, w.shouldExtract)
-				// If item returned null but we're removing items within the structure(not the item itself),
-				// preserve the empty container structure
-				if item.IsNull() && !w.shouldExtract {
-					if wasMap {
-						item = value.NewValueInterface(map[string]interface{}{})
-					} else if wasList {
-						item = value.NewValueInterface([]interface{}{})
-					}
-				}
 			}
 			newItems = append(newItems, item.Unstructured())
 		}
 	}
-	// Preserve empty lists (non-nil) instead of converting to null when items were matched and removed
-	if len(newItems) > 0 || (hadMatches && !w.shouldExtract) {
+	if len(newItems) > 0 {
 		w.out = newItems
 	}
 	return nil
@@ -156,7 +141,6 @@
 	}
 
 	newMap := map[string]interface{}{}
-	hadMatches := false
 	m.Iterate(func(k string, val value.Value) bool {
 		pe := fieldpath.PathElement{FieldName: &k}
 		path, _ := fieldpath.MakePath(pe)
@@ -174,19 +158,7 @@
 			return true
 		}
 		if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
-			hadMatches = true
-			wasMap := val.IsMap()
-			wasList := val.IsList()
 			val = removeItemsWithSchema(val, subset, w.schema, fieldType, w.shouldExtract)
-			// If val returned null but we're removing items within the structure (not the field itself),
-			// preserve the empty container structure
-			if val.IsNull() && !w.shouldExtract {
-				if wasMap {
-					val = value.NewValueInterface(map[string]interface{}{})
-				} else if wasList {
-					val = value.NewValueInterface([]interface{}{})
-				}
-			}
 		} else {
 			// don't save values not on the path when we shouldExtract.
 			if w.shouldExtract {
@@ -196,8 +168,7 @@
 		newMap[k] = val.Unstructured()
 		return true
 	})
-	// Preserve empty maps (non-nil) instead of converting to null when items were matched and removed
-	if len(newMap) > 0 || (hadMatches && !w.shouldExtract) {
+	if len(newMap) > 0 {
 		w.out = newMap
 	}
 	return nil
diff --git a/typed/remove_test.go b/typed/remove_test.go
index 7685065..df59c16 100644
--- a/typed/remove_test.go
+++ b/typed/remove_test.go
@@ -281,7 +281,7 @@
 	quadruplets: []removeQuadruplet{{
 		`{"setBool":[false]}`,
 		_NS(_P("setBool", _V(false))),
-		`{"setBool":[]}`,
+		`{"setBool":null}`,
 		`{"setBool":[false]}`,
 	}, {
 		`{"setBool":[false]}`,
@@ -671,7 +671,7 @@
 		_NS(
 			_P("mapOfMapsRecursive", "a"),
 		),
-		`{"mapOfMapsRecursive":{}}`,
+		`{"mapOfMapsRecursive"}`,
 		`{"mapOfMapsRecursive": {"a":null}}`,
 	}, {
 		// second-level map
@@ -679,7 +679,7 @@
 		_NS(
 			_P("mapOfMapsRecursive", "a", "b"),
 		),
-		`{"mapOfMapsRecursive":{"a":{}}}`,
+		`{"mapOfMapsRecursive":{"a":null}}`,
 		`{"mapOfMapsRecursive": {"a":{"b":null}}}`,
 	}, {
 		// third-level map
@@ -687,7 +687,7 @@
 		_NS(
 			_P("mapOfMapsRecursive", "a", "b", "c"),
 		),
-		`{"mapOfMapsRecursive":{"a":{"b":{}}}}`,
+		`{"mapOfMapsRecursive":{"a":{"b":null}}}`,
 		`{"mapOfMapsRecursive": {"a":{"b":{"c":null}}}}`,
 	}, {
 		// empty list