File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -88,14 +88,25 @@ func (id *ObjectID) UnmarshalJSON(b []byte) error {
88
88
copy (id [:], b )
89
89
default :
90
90
// Extended JSON
91
- m := make ( map [ string ] string )
92
- err := json .Unmarshal (b , & m )
91
+ var res interface {}
92
+ err := json .Unmarshal (b , & res )
93
93
if err != nil {
94
94
return err
95
95
}
96
- str , ok := m [ "$oid" ]
96
+ str , ok := res .( string )
97
97
if ! ok {
98
- return errors .New ("not an extended JSON ObjectID" )
98
+ m , ok := res .(map [string ]interface {})
99
+ if ! ok {
100
+ return errors .New ("not an extended JSON ObjectID" )
101
+ }
102
+ oid , ok := m ["$oid" ]
103
+ if ! ok {
104
+ return errors .New ("not an extended JSON ObjectID" )
105
+ }
106
+ str , ok = oid .(string )
107
+ if ! ok {
108
+ return errors .New ("not an extended JSON ObjectID" )
109
+ }
99
110
}
100
111
101
112
if len (str ) != 24 {
You can’t perform that action at this time.
0 commit comments