diff --git a/common/structure/structure.go b/common/structure/structure.go index 840e4f6c..d43dec03 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -517,6 +517,10 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e fieldName = tagValue } + if tagValue == "-" { + continue + } + rawMapKey := reflect.ValueOf(fieldName) rawMapVal := dataVal.MapIndex(rawMapKey) if !rawMapVal.IsValid() { diff --git a/common/structure/structure_test.go b/common/structure/structure_test.go index 06dffd0f..c79c2eb4 100644 --- a/common/structure/structure_test.go +++ b/common/structure/structure_test.go @@ -308,3 +308,27 @@ func TestStructure_Ignore(t *testing.T) { assert.Nil(t, err) assert.Equal(t, s.MustIgnore, "oldData") } + +func TestStructure_IgnoreInNest(t *testing.T) { + rawMap := map[string]any{ + "-": "newData", + } + + type TP struct { + MustIgnore string `test:"-"` + } + + s := struct { + TP + }{TP{MustIgnore: "oldData"}} + + err := decoder.Decode(rawMap, &s) + assert.Nil(t, err) + assert.Equal(t, s.MustIgnore, "oldData") + + // test omitempty + delete(rawMap, "-") + err = decoder.Decode(rawMap, &s) + assert.Nil(t, err) + assert.Equal(t, s.MustIgnore, "oldData") +}