If an encoder is registered for an interface type, we'll call that encoder for all types that implement that interface as well. This was done so we could register encoders for types like bson.Marshaler and they would be called for all structs that implement bson.Marshaler. Users may want more fine-grained behavior, however. If an encoder is registered for io.Reader, a user may only want it to be called when marshalling an io.Reader and use the regular struct codec when marshalling a concrete type that implements io.Reader. The proposed way to do this is the following:
- Deprecate RegisterEncoder
- Add a new function to register a type encoder. In the case of interface types, the encoder will only be called when marshalling the interface type, not a concrete type that implements it.
- Add a new function to register a "hook" encoder. This will only accept interface types and the encoder will be called for any types that implement the interface. We'll use this for interfaces like bson.Marshaler
Everything listed above applies to decoders as well.