@@ -27,6 +27,7 @@ An introduction to using resources with kubectl can be found in [the object mana
27
27
- [ Categories] ( #categories )
28
28
- [ Idempotency] ( #idempotency )
29
29
- [ Optional vs. Required] ( #optional-vs-required )
30
+ - [ Nullable] ( #nullable )
30
31
- [ Defaulting] ( #defaulting )
31
32
- [ Static Defaults] ( #static-defaults )
32
33
- [ Admission Controlled Defaults] ( #admission-controlled-defaults )
@@ -909,6 +910,26 @@ In these cases, pointers are not needed, as the zero value indicates to the stru
909
910
910
911
This can be beneficial to API authors, as it reduces the complexity of the API, and reduces the risk of nil pointer exceptions in controllers.
911
912
913
+ # # Nullable
914
+
915
+ The `+nullable` comment tag allows the json `null` value to be a valid value
916
+ for a field. The `null` value is serialized only when a field is a pointer
917
+ in the Go definition, and does not have the `omitempty` json tag, or sometimes where a
918
+ custom marshal function is implemented.
919
+
920
+ For example, a map field marked with `+nullable` would accept either `foo : null` or `foo: {}`.
921
+
922
+ Usage of `+nullable` is discouraged as it introduces several issues :
923
+ - It is not compatible with json merge patching.
924
+ - From the [JSON Merge Patch RFC](https://tools.ietf.org/html/rfc7386#section-1):
925
+ > Null values in the merge patch are given special meaning to indicate the removal of existing values in the target.
926
+ - Explicit `null` values are not persisted in proto serializations.
927
+ - ` null` values are not supported by Server-Side Apply applyconfiguration types.
928
+ - A persisted `null` value would not round-trip through the applyconfiguration type
929
+ encode/decode cycle.
930
+
931
+ Avoid designing APIs that require the distinction between unset and `null`.
932
+
912
933
# # Defaulting
913
934
914
935
In general we want default values to be explicitly represented in our APIs,
0 commit comments