fix: mapping FillDefault is optional! bug (#3940)
This commit is contained in:
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user