globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 232 forks source link

Add support for encoding.TextMarshaler/TextUnmarshaler #362

Open zigazeljko opened 5 years ago

zigazeljko commented 5 years ago

encoding.TextMarshaler is a common way to provide a general marshaling logic which is repected by encoding/json and many other marshalers, e.g. https://github.com/go-yaml/yaml (https://github.com/go-yaml/yaml/blob/v2/encode.go#L135). Currently the bson package only supports custom marshaling logic via the bson.Getter interface, which is BSON-specific and therefore requires writing custom BSON-specific marshaling logic (clumsy, especially for types from third-party packages).

Would it be possible to also support encoding.TextMarshaler (and encoding.TextUnmarshaler) when marshaling/unmarshaling bson (in addition to bson.Getter and bson.Setter)? I can make a PR implementing it.

Dragomir-Ivanov commented 5 years ago

@zigazeljko Take a look at #353