Details
-
Bug
-
Resolution: Works as Designed
-
Major - P3
-
None
-
None
-
None
Description
package main
|
|
|
import (
|
"encoding/json"
|
"fmt"
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
)
|
|
|
func main() {
|
td := struct {
|
EmptyExample primitive.ObjectID `json:",omitempty"`
|
}{}
|
|
|
out, err := json.Marshal(td)
|
if err != nil {
|
panic(err)
|
}
|
|
|
fmt.Println(string(out))
|
}
|
You get the following output `
{"EmptyExample":"000000000000000000000000"}` instead of an omitted field because the `ObjectID` type is an alias for a 12 byte slice and it doesn't have a custom json marshaler.