|
|
@ -731,15 +731,36 @@ func (u *Unmarshaler) processNamedFieldWithValue(fieldType reflect.Type, value r
|
|
|
|
return u.processFieldNotFromString(fieldType, value, vp, opts, fullName)
|
|
|
|
return u.processFieldNotFromString(fieldType, value, vp, opts, fullName)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
if u.opts.fromString || opts.fromString() {
|
|
|
|
if u.opts.fromString || opts.fromString() {
|
|
|
|
|
|
|
|
return u.processNamedFieldWithValueFromString(fieldType, value, mapValue,
|
|
|
|
|
|
|
|
key, opts, fullName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return u.processFieldNotFromString(fieldType, value, vp, opts, fullName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) processNamedFieldWithValueFromString(fieldType reflect.Type, value reflect.Value,
|
|
|
|
|
|
|
|
mapValue interface{}, key string, opts *fieldOptionsWithContext, fullName string) error {
|
|
|
|
valueKind := reflect.TypeOf(mapValue).Kind()
|
|
|
|
valueKind := reflect.TypeOf(mapValue).Kind()
|
|
|
|
if valueKind != reflect.String {
|
|
|
|
if valueKind != reflect.String {
|
|
|
|
return fmt.Errorf("error: the value in map is not string, but %s", valueKind)
|
|
|
|
return fmt.Errorf("the value in map is not string, but %s", valueKind)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
options := opts.options()
|
|
|
|
options := opts.options()
|
|
|
|
if len(options) > 0 {
|
|
|
|
if len(options) > 0 {
|
|
|
|
if !stringx.Contains(options, mapValue.(string)) {
|
|
|
|
var checkValue string
|
|
|
|
return fmt.Errorf(`error: value "%s" for field "%s" is not defined in options "%v"`,
|
|
|
|
switch mt := mapValue.(type) {
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
|
|
|
checkValue = mt
|
|
|
|
|
|
|
|
case json.Number:
|
|
|
|
|
|
|
|
checkValue = mt.String()
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Errorf("the value in map is not string or json.Number, but %s",
|
|
|
|
|
|
|
|
valueKind.String())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !stringx.Contains(options, checkValue) {
|
|
|
|
|
|
|
|
return fmt.Errorf(`value "%s" for field "%s" is not defined in options "%v"`,
|
|
|
|
mapValue, key, options)
|
|
|
|
mapValue, key, options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -747,10 +768,6 @@ func (u *Unmarshaler) processNamedFieldWithValue(fieldType reflect.Type, value r
|
|
|
|
return fillPrimitive(fieldType, value, mapValue, opts, fullName)
|
|
|
|
return fillPrimitive(fieldType, value, mapValue, opts, fullName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return u.processFieldNotFromString(fieldType, value, vp, opts, fullName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) processNamedFieldWithoutValue(fieldType reflect.Type, value reflect.Value,
|
|
|
|
func (u *Unmarshaler) processNamedFieldWithoutValue(fieldType reflect.Type, value reflect.Value,
|
|
|
|
opts *fieldOptionsWithContext, fullName string) error {
|
|
|
|
opts *fieldOptionsWithContext, fullName string) error {
|
|
|
|
derefedType := Deref(fieldType)
|
|
|
|
derefedType := Deref(fieldType)
|
|
|
|