From fd62f2a63d4f59b348939dac12c9fad755aace0d Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 25 Jan 2024 01:52:34 +0530 Subject: [PATCH 1/2] Include empty scalars in dynamic representation --- libs/dyn/convert/end_to_end_test.go | 17 +++++++++++++++++ libs/dyn/convert/from_typed.go | 5 ----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libs/dyn/convert/end_to_end_test.go b/libs/dyn/convert/end_to_end_test.go index fbb8433629..5175c36f6f 100644 --- a/libs/dyn/convert/end_to_end_test.go +++ b/libs/dyn/convert/end_to_end_test.go @@ -27,6 +27,7 @@ func TestAdditional(t *testing.T) { MapToPointer map[string]*string `json:"map_to_pointer"` SliceOfPointer []*string `json:"slice_of_pointer"` NestedStruct StructType `json:"nested_struct"` + MapOfString map[string]string `json:"map_of_string"` } t.Run("nil", func(t *testing.T) { @@ -58,4 +59,20 @@ func TestAdditional(t *testing.T) { SliceOfPointer: []*string{nil}, }) }) + + t.Run("map with one value", func(t *testing.T) { + assertFromTypedToTypedEqual(t, Tmp{ + MapOfString: map[string]string{ + "key": "value", + }, + }) + }) + + t.Run("map with empty val", func(t *testing.T) { + assertFromTypedToTypedEqual(t, Tmp{ + MapOfString: map[string]string{ + "key": "", + }, + }) + }) } diff --git a/libs/dyn/convert/from_typed.go b/libs/dyn/convert/from_typed.go index 0659d1cd78..46bbb3efa8 100644 --- a/libs/dyn/convert/from_typed.go +++ b/libs/dyn/convert/from_typed.go @@ -142,11 +142,6 @@ func fromTypedString(src reflect.Value, ref dyn.Value) (dyn.Value, error) { return dyn.V(value), nil case dyn.KindNil: - // This field is not set in the reference, so we only include it if it has a non-zero value. - // Otherwise, we would always include all zero valued fields. - if src.IsZero() { - return dyn.NilValue, nil - } return dyn.V(src.String()), nil } From 8d0cbe664a808e53ce33966cb5e9f1c88ba57a12 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 25 Jan 2024 01:58:12 +0530 Subject: [PATCH 2/2] - --- libs/dyn/convert/end_to_end_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/dyn/convert/end_to_end_test.go b/libs/dyn/convert/end_to_end_test.go index 5175c36f6f..f0115c54ba 100644 --- a/libs/dyn/convert/end_to_end_test.go +++ b/libs/dyn/convert/end_to_end_test.go @@ -28,6 +28,7 @@ func TestAdditional(t *testing.T) { SliceOfPointer []*string `json:"slice_of_pointer"` NestedStruct StructType `json:"nested_struct"` MapOfString map[string]string `json:"map_of_string"` + MapOfBool map[string]bool `json:"map_of_bool"` } t.Run("nil", func(t *testing.T) { @@ -75,4 +76,13 @@ func TestAdditional(t *testing.T) { }, }) }) + + // Without the changes in this PR, this test case would fail + t.Run("map with empty val", func(t *testing.T) { + assertFromTypedToTypedEqual(t, Tmp{ + MapOfBool: map[string]bool{ + "key": false, + }, + }) + }) }