This PR makes it possible to use custom type converters on interface types. It works by resolving interfaces to concrete types before the conversion takes place.
It seems to be impossible to define use interface types for SrcType or DstType of the type converter. Internally the copier will resolve these types to the actual underlying types, because of how reflect.TypeOf works, e.g.:
type MyI interface{ A() }
type MyS struct{}
func (MyS) A() {}
var m MyI = MyS{}
fmt.Println(reflect.TypeOf(m)) // prints: MyS
When the copier encounters a struct field with an interface type, it then wouldn't know what type converter to use. This PR fixes this issue, so that this actually works:
TL;DR
This PR makes it possible to use custom type converters on interface types. It works by resolving interfaces to concrete types before the conversion takes place.
It seems to be impossible to define use interface types for
SrcType
orDstType
of the type converter. Internally the copier will resolve these types to the actual underlying types, because of howreflect.TypeOf
works, e.g.:When the copier encounters a struct field with an interface type, it then wouldn't know what type converter to use. This PR fixes this issue, so that this actually works: