Encoding concrete type for a custom registry

@Salvatore_Mazzarino welcome and thanks for the question! Here is a Go Playground example of how to implement a ValueEncoder that does something similar to you’re describing.

However, you should strongly consider the much simpler approach of adding a MarshalBSON method on myType (so it implements the bson.Marshaler interface) instead of using a Registry. Here is a Go Playground example of a MarshalBSON method that does something similar to what you’re describing.

Another tip: If you end up using a Registry, use bson.NewRegistry to create a registry with the default codecs registered, instead of bsoncodec.NewRegistry (which creates an empty registry).