|
|
@ -205,10 +205,10 @@ func (u *Unmarshaler) processFieldNotFromString(field reflect.StructField, value
|
|
|
|
return u.processFieldStruct(field, value, mapValue, fullName)
|
|
|
|
return u.processFieldStruct(field, value, mapValue, fullName)
|
|
|
|
case valueKind == reflect.Map && typeKind == reflect.Map:
|
|
|
|
case valueKind == reflect.Map && typeKind == reflect.Map:
|
|
|
|
return u.fillMap(field, value, mapValue)
|
|
|
|
return u.fillMap(field, value, mapValue)
|
|
|
|
case valueKind == reflect.String && typeKind == reflect.Slice:
|
|
|
|
|
|
|
|
return u.fillSliceFromString(fieldType, value, mapValue)
|
|
|
|
|
|
|
|
case valueKind == reflect.String && typeKind == reflect.Map:
|
|
|
|
case valueKind == reflect.String && typeKind == reflect.Map:
|
|
|
|
return u.fillMapFromString(value, mapValue)
|
|
|
|
return u.fillMapFromString(value, mapValue)
|
|
|
|
|
|
|
|
case valueKind == reflect.String && typeKind == reflect.Slice:
|
|
|
|
|
|
|
|
return u.fillSliceFromString(fieldType, value, mapValue)
|
|
|
|
case valueKind == reflect.String && derefedFieldType == durationType:
|
|
|
|
case valueKind == reflect.String && derefedFieldType == durationType:
|
|
|
|
return fillDurationValue(fieldType.Kind(), value, mapValue.(string))
|
|
|
|
return fillDurationValue(fieldType.Kind(), value, mapValue.(string))
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -444,6 +444,27 @@ func (u *Unmarshaler) fillMap(field reflect.StructField, value reflect.Value, ma
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) fillMapFromString(value reflect.Value, mapValue interface{}) error {
|
|
|
|
|
|
|
|
if !value.CanSet() {
|
|
|
|
|
|
|
|
return errValueNotSettable
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch v := mapValue.(type) {
|
|
|
|
|
|
|
|
case fmt.Stringer:
|
|
|
|
|
|
|
|
if err := jsonx.UnmarshalFromString(v.String(), value.Addr().Interface()); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
|
|
|
if err := jsonx.UnmarshalFromString(v, value.Addr().Interface()); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return errUnsupportedType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value, mapValue interface{}) error {
|
|
|
|
func (u *Unmarshaler) fillSlice(fieldType reflect.Type, value reflect.Value, mapValue interface{}) error {
|
|
|
|
if !value.CanSet() {
|
|
|
|
if !value.CanSet() {
|
|
|
|
return errValueNotSettable
|
|
|
|
return errValueNotSettable
|
|
|
@ -532,23 +553,6 @@ func (u *Unmarshaler) fillSliceFromString(fieldType reflect.Type, value reflect.
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) fillMapFromString(value reflect.Value, mapValue interface{}) error {
|
|
|
|
|
|
|
|
switch v := mapValue.(type) {
|
|
|
|
|
|
|
|
case fmt.Stringer:
|
|
|
|
|
|
|
|
if err := jsonx.UnmarshalFromString(v.String(), value.Addr().Interface()); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
|
|
|
if err := jsonx.UnmarshalFromString(v, value.Addr().Interface()); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return errUnsupportedType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
|
|
|
func (u *Unmarshaler) fillSliceValue(slice reflect.Value, index int,
|
|
|
|
baseKind reflect.Kind, value interface{}) error {
|
|
|
|
baseKind reflect.Kind, value interface{}) error {
|
|
|
|
ithVal := slice.Index(index)
|
|
|
|
ithVal := slice.Index(index)
|
|
|
|