I have a function which must accept object type. Then it must unmarshal XML to an object of a given type.
Getting object type with reflect:
objType := reflect.TypeOf(CustomObjectType{})
UnmarshalWorker(objType)
Unmarshal function:
func UnmarshalFeedGeneric (data []byte,objType reflect.Type) {
unm := reflect.New(objType)
err := xml.Unmarshal(data, unm.Interface())
}
And 'unm' always return nil value.
fmt.Println(unm)
fmt.Println(unm.Elem())
fmt.Println(unm.Interface())
Output:
<*main.CustomObjectType Value>
<main.CustomObjectType Value>
&{ <nil> 0}