fix: mapping FillDefault is optional! bug (#3940)

master^2
MarkJoyMa 8 months ago committed by GitHub
parent 1f63cbe9c6
commit 88aab8f635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

@ -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"`

Loading…
Cancel
Save