Skip to content

Commit

Permalink
AMEND: Add custom marshalling for _id
Browse files Browse the repository at this point in the history
  • Loading branch information
jpahm committed Nov 7, 2023
1 parent 65eb619 commit c8abcd5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions api/schema/objects.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package schema

import (
"bytes"
"time"

"go.mongodb.org/mongo-driver/bson/primitive"
Expand All @@ -14,8 +13,8 @@ type IdWrapper struct {

// Custom JSON marshalling for ObjectID to marshal ObjectIDs correctly
func (id IdWrapper) MarshalJSON() (data []byte, err error) {
jsonString := `{$oid:"` + id.String() + `"}`
return bytes.NewBufferString(jsonString).Bytes(), nil
jsonString := `{"$oid":"` + id.String() + `"}`
return []byte(jsonString), nil
}

type Course struct {
Expand Down

0 comments on commit c8abcd5

Please sign in to comment.