We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b7c48f5 commit 228ac2dCopy full SHA for 228ac2d
bson/objectid/objectid.go
@@ -77,6 +77,11 @@ func FromHex(s string) (ObjectID, error) {
77
return oid, nil
78
}
79
80
+// MarshalJSON returns the ObjectID as a string
81
+func (id *ObjectID) MarshalJSON() ([]byte, error) {
82
+ return json.Marshal(id.Hex())
83
+}
84
+
85
// UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 64 bytes long, it
86
// will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes
87
// long, it will be populated with the BSON representation of the ObjectID. Otherwise, it will
0 commit comments