Repository: kubernetes
Issue: 'spec in body must be of type object: "null"' when removing a field using SSA
Labels: kind/bug,sig/api-machinery,wg/api-expression,triage/accepted

### What happened?

I'm developing a controller that uses server-side apply and must be able to add and remove fields in the spec of custom resources. I am able to create an object with an empty spec using SSA, then add a field with data with a second SSA patch. When I attempt to remove the field using a third SSA patch, I get an error:
```
The Test "t" is invalid: spec: Invalid value: "null": spec in body must be of type object: "null"
```


### What did you expect to happen?

I expect that the field is removed when an empty spec is supplied in a SSA patch.

### How can we reproduce it (as minimally and precisely as possible)?

```console
$ kubectl apply -f- << EOF
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tests.example.com
spec:
  group: example.com
  versions:
  - name: v1alpha1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              x:
                type: string
  scope: Namespaced
  names:
    plural: tests
    singular: test
    kind: Test
EOF
customresourcedefinition.apiextensions.k8s.io/tests.example.com created

$ kubectl apply --server-side --force-conflicts --field-manager='mgr' -f- << EOF
apiVersion: example.com/v1alpha1
kind: Test
metadata:
  name: t
spec: {}
EOF
test.example.com/t serverside-applied

$ kubectl apply --server-side --force-conflicts --field-manager='mgr' -f- << EOF
apiVersion: example.com/v1alpha1
kind: Test
metadata:
  name: t
spec:
  x: xoxo
EOF
test.example.com/t serverside-applied

$ kubectl apply --server-side --force-conflicts --field-manager='mgr' -f- << EOF
apiVersion: example.com/v1alpha1
kind: Test
metadata:
  name: t
spec: {}
EOF
The Test "t" is invalid: spec: Invalid value: "null": spec in body must be of type object: "null"
```

### Anything else we need to know?

* Client-side apply was not used at any point.
* This sounds very similar to #103011, but the reproducer listed there works fine.
* This is probably a regression. I'm certain it used to work in a previous version but unfortunately I don't know which version that was.


### Kubernetes version

```
1.26.3
```
<details>

```console
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:14:41Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"darwin/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.3", GitCommit:"9e644106593f3f4aa98f8a84b23db5fa378900bd", GitTreeState:"clean", BuildDate:"2023-03-15T13:33:12Z", GoVersion:"go1.19.7", Compiler:"gc", Platform:"linux/amd64"}
```
</details>

### Cloud provider

bare metal installation

### OS version

Debian testing (bookworm)

### Install tools

_No response_

### Container runtime (CRI) and version (if applicable)

_No response_

### Related plugins (CNI, CSI, ...) and versions (if applicable)

_No response_