|
|
@ -1,6 +1,7 @@
|
|
|
|
package mapping
|
|
|
|
package mapping
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
@ -318,6 +319,28 @@ func (u *Unmarshaler) processFieldStructWithMap(field reflect.StructField, value
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) processFieldTextUnmarshaler(field reflect.StructField, value reflect.Value,
|
|
|
|
|
|
|
|
mapValue interface{}) (bool, error) {
|
|
|
|
|
|
|
|
var tval encoding.TextUnmarshaler
|
|
|
|
|
|
|
|
var ok bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if field.Type.Kind() == reflect.Ptr {
|
|
|
|
|
|
|
|
tval, ok = value.Interface().(encoding.TextUnmarshaler)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tval, ok = value.Addr().Interface().(encoding.TextUnmarshaler)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
|
|
switch mv := mapValue.(type) {
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
|
|
|
return true, tval.UnmarshalText([]byte(mv))
|
|
|
|
|
|
|
|
case []byte:
|
|
|
|
|
|
|
|
return true, tval.UnmarshalText(mv)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect.Value,
|
|
|
|
func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect.Value,
|
|
|
|
m Valuer, fullName string) error {
|
|
|
|
m Valuer, fullName string) error {
|
|
|
|
key, opts, err := u.parseOptionsWithContext(field, m, fullName)
|
|
|
|
key, opts, err := u.parseOptionsWithContext(field, m, fullName)
|
|
|
@ -348,8 +371,16 @@ func (u *Unmarshaler) processNamedFieldWithValue(field reflect.StructField, valu
|
|
|
|
return fmt.Errorf("field %s mustn't be nil", key)
|
|
|
|
return fmt.Errorf("field %s mustn't be nil", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !value.CanSet() {
|
|
|
|
|
|
|
|
return fmt.Errorf("field %s is not settable", key)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maybeNewValue(field, value)
|
|
|
|
maybeNewValue(field, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if yes, err := u.processFieldTextUnmarshaler(field, value, mapValue); yes {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fieldKind := Deref(field.Type).Kind()
|
|
|
|
fieldKind := Deref(field.Type).Kind()
|
|
|
|
switch fieldKind {
|
|
|
|
switch fieldKind {
|
|
|
|
case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct:
|
|
|
|
case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct:
|
|
|
|