From 678dac81ccb3a53ad7da13c4e3af3acaa45e7b72 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Thu, 12 Sep 2024 11:17:25 +0200 Subject: [PATCH] Test Signed-off-by: Israel Blancas --- apis/v1beta1/config.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apis/v1beta1/config.go b/apis/v1beta1/config.go index 61fecb3ad1..4eab8d485d 100644 --- a/apis/v1beta1/config.go +++ b/apis/v1beta1/config.go @@ -90,7 +90,22 @@ func (c *AnyConfig) MarshalJSON() ([]byte, error) { if c == nil { return []byte("{}"), nil } - return json.Marshal(c.Object) + return json.Marshal(c.convertNilToEmptyMap(c.Object)) +} + +func (c *AnyConfig) convertNilToEmptyMap(m map[string]interface{}) map[string]interface{} { + result := make(map[string]interface{}) + for k, v := range m { + switch val := v.(type) { + case nil: + result[k] = map[string]interface{}{} + case map[string]interface{}: + result[k] = c.convertNilToEmptyMap(val) + default: + result[k] = v + } + } + return result } // Pipeline is a struct of component type to a list of component IDs.