When a codec is created for a byte-slice type at
it ignores the fact that the type could be implementing the
json.Marshaler or
encoding.TextMarshaler interfaces. This should be considered in priority, to be compliant with the standard library.
The following playground demonstrates the issue:
https://play.golang.org/p/Bm0d3jsWkZf
The relevant code can be found in the standard library at https://github.com/golang/go/blob/da4d58587e0e4028ea384580053c3c455127e446/src/encoding/json/encode.go#L415
The function newTypeEncoder checks in priority if the reflect.Value implements one of the interfaces.