bzp2010 commented on code in PR #2538:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2538#discussion_r2315229580
##########
api/adc/types.go:
##########
@@ -505,6 +505,20 @@ func (n *UpstreamNodes) UnmarshalJSON(p []byte) error {
return nil
}
+// MarshalJSON implements the json.Marshaler interface for UpstreamNodes.
+// By default, Go serializes a nil slice as JSON null. However, for
compatibility
+// with APISIX semantics, we want a nil UpstreamNodes to be encoded as an empty
+// array ([]) instead of null. Non-nil slices are marshaled as usual.
+//
+// See APISIX upstream nodes schema definition for details:
+//
https://github.com/apache/apisix/blob/77dacda31277a31d6014b4970e36bae2a5c30907/apisix/schema_def.lua#L295-L338
+func (n UpstreamNodes) MarshalJSON() ([]byte, error) {
+ if n == nil {
+ return []byte("[]"), nil
Review Comment:
Isn't this achieved by filling empty slices as fallback values? This
approach doesn't seem conducive to maintenance.
An overridden implementation would require digging deep into the code to
discover.
https://go.dev/play/p/rB6BCY0n670
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]