diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go index 982d69e5..fbaeb69a 100644 --- a/core/mapping/unmarshaler.go +++ b/core/mapping/unmarshaler.go @@ -428,6 +428,10 @@ func (u *Unmarshaler) parseOptionsWithContext(field reflect.StructField, m Value } } + if u.opts.fillDefault { + return key, &options.fieldOptionsWithContext, nil + } + optsWithContext, err := options.toOptionsWithContext(key, m, fullName) if err != nil { return "", nil, err diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go index fdbdf4e0..c258e3a6 100644 --- a/core/mapping/unmarshaler_test.go +++ b/core/mapping/unmarshaler_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" + "github.com/zeromicro/go-zero/core/stringx" ) @@ -5411,6 +5412,16 @@ func TestFillDefaultUnmarshal(t *testing.T) { assert.Equal(t, "c", st.C) }) + t.Run("optional !", func(t *testing.T) { + type St struct { + A string `json:",optional"` + B string `json:",optional=!A"` + } + var st = St{} + err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st) + assert.NoError(t, err) + }) + t.Run("has value", func(t *testing.T) { type St struct { A string `json:",default=a"`