diff --git a/libs/dyn/convert/end_to_end_test.go b/libs/dyn/convert/end_to_end_test.go index fbb8433629..f0115c54ba 100644 --- a/libs/dyn/convert/end_to_end_test.go +++ b/libs/dyn/convert/end_to_end_test.go @@ -27,6 +27,8 @@ 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"` + MapOfBool map[string]bool `json:"map_of_bool"` } t.Run("nil", func(t *testing.T) { @@ -58,4 +60,29 @@ 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": "", + }, + }) + }) + + // 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, + }, + }) + }) } 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 }