Hey @Mike_71464, thanks for the question and for the helpful examples!
In Go Driver v2, the bson.ValueMarshaler interface changed to:
type ValueMarshaler interface {
MarshalBSONValue() (typ byte, data []byte, err error)
}
In v1, the interface was:
type ValueMarshaler interface {
MarshalBSONValue() (bsontype.Type, []byte, error)
}
The first return value changed from bsontype.Type to byte. The purpose is to allow Go modules to implement the bson.ValueMarshaler interface without depending directly on the Go Driver module.
To fix your v2 example, change the type of the first return value of the MarshalBSONValue methods to byte instead of bson.Type. See an updated version of your code samples here. You can also add a compile-time check to confirm your types implement the bson.ValueMarshaler interface like this:
var _ bson.ValueMarshaler = String{}
var _ bson.ValueMarshaler = StringArray{}
Please let me know if that fixes your issue! By the way, which release notes are you looking at for breaking changes?