Skip to content

Commit 40d386b

Browse files
committed
Revert "feat/conf_map_required (#4405)"
This reverts commit 12071d1.
1 parent 6138f85 commit 40d386b

File tree

2 files changed

+1
-41
lines changed

2 files changed

+1
-41
lines changed

core/mapping/unmarshaler.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,16 +919,12 @@ func (u *Unmarshaler) processNamedFieldWithoutValue(fieldType reflect.Type, valu
919919
}
920920

921921
switch fieldKind {
922-
case reflect.Array, reflect.Slice:
922+
case reflect.Array, reflect.Map, reflect.Slice:
923923
if !opts.optional() {
924924
return u.processFieldNotFromString(fieldType, value, valueWithParent{
925925
value: emptyMap,
926926
}, opts, fullName)
927927
}
928-
case reflect.Map:
929-
if !opts.optional() {
930-
return newInitError(fullName)
931-
}
932928
case reflect.Struct:
933929
if !opts.optional() {
934930
required, err := structValueRequired(u.key, derefedType)

core/mapping/unmarshaler_test.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,42 +2432,6 @@ func TestUnmarshalMapOfStruct(t *testing.T) {
24322432
}
24332433
assert.Error(t, UnmarshalKey(m, &v))
24342434
})
2435-
2436-
t.Run("map set", func(t *testing.T) {
2437-
type Inner1 struct {
2438-
M map[string]string
2439-
}
2440-
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner1{}))
2441-
assert.NoError(t, UnmarshalKey(map[string]any{
2442-
"M": map[string]string{},
2443-
}, &Inner1{}))
2444-
2445-
type Inner2 struct {
2446-
Inner1
2447-
}
2448-
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner2{}))
2449-
assert.NoError(t, UnmarshalKey(map[string]any{
2450-
"M": map[string]string{},
2451-
}, &Inner2{}))
2452-
2453-
type Inner3 struct {
2454-
C Inner1
2455-
}
2456-
assert.Error(t, UnmarshalKey(map[string]any{}, &Inner3{}))
2457-
assert.NoError(t, UnmarshalKey(map[string]any{
2458-
"C": map[string]any{
2459-
"M": map[string]string{},
2460-
},
2461-
}, &Inner3{}))
2462-
2463-
type Inner4 struct {
2464-
M map[string]string `json:",optional"`
2465-
}
2466-
assert.NoError(t, UnmarshalKey(map[string]any{}, &Inner4{}))
2467-
assert.NoError(t, UnmarshalKey(map[string]any{
2468-
"M": map[string]string{},
2469-
}, &Inner4{}))
2470-
})
24712435
}
24722436

24732437
func TestUnmarshalSlice(t *testing.T) {

0 commit comments

Comments
 (0)