mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Automatic merge from submit-queue Ensure slices are serialized as zero-length, not null Fixes https://github.com/kubernetes/kubernetes/issues/43203 null serialization of slices to prevent NPE errors in clients that store and expect to receive non-null JSON values in these fields. Ensures when we are converting to an external slice field that will be serialized even if empty (has `json` tag that does not include `omitempty`), we populate it with `[]`, not `nil` Other places I considered putting this logic instead: * When unmarshaling * Would have to be done for both protobuf and ugorji * Would still have to be done here (or on marshal) to handle cases where we construct objects to return * When marshaling * Would have to switch to use custom json marshaler (currently we use stdlib) * When defaulting * Defaulting isn't run on some fields, notably, pod template in rc/deployment spec * Would still have to be done here (or on marshal) to handle cases where we construct objects to return ```release-note API fields that previously serialized null arrays as `null` and empty arrays as `[]` no longer distinguish between those values and always output `[]` when serializing to JSON. ```