the reason your snippet does not work is that you pass in *payload as T
and the zero value of a pointer type is nil and json unmarshal cannot
with nil pointer values. so would need to pass in payload as T and
*payload as P and somehow explain that P is *T and a
encoding.BinaryUnmarshaler. I am not versed enough in go generics to
know the solution, but would propose to take a simpler approach if possible.