Files
kubernetes/pkg
Kubernetes Submit Queue 51beb16ede Merge pull request #43422 from liggitt/convert-null-list
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.
```
2017-03-21 11:46:19 -07:00
..
2017-03-20 23:57:38 -04:00
API
2017-02-28 23:05:40 -08:00
2017-03-20 23:57:38 -04:00
2017-03-10 07:24:38 +01:00
2017-01-19 09:50:16 -05:00
2017-03-20 23:57:38 -04:00
2017-03-02 10:23:58 +01:00
2017-03-02 08:56:26 +01:00