@@ -172,6 +172,37 @@ func TestCounterOverflow(t *testing.T) {
172
172
require .Equal (t , uint32 (0 ), objectIDCounter )
173
173
}
174
174
175
+ func TestObjectID_MarshalJSONMap (t * testing.T ) {
176
+ type mapOID struct {
177
+ Map map [ObjectID ]string
178
+ }
179
+
180
+ oid := NewObjectID ()
181
+ expectedJson := []byte (fmt .Sprintf (`{"Map":{%q:"foo"}}` , oid .Hex ()))
182
+ data := mapOID {
183
+ Map : map [ObjectID ]string {oid : "foo" },
184
+ }
185
+
186
+ out , err := json .Marshal (& data )
187
+ require .NoError (t , err )
188
+ require .Equal (t , expectedJson , out )
189
+ }
190
+
191
+ func TestObjectID_UnmarshalJSONMap (t * testing.T ) {
192
+ type mapOID struct {
193
+ Map map [ObjectID ]string
194
+ }
195
+ oid := NewObjectID ()
196
+ mapOIDJson := []byte (fmt .Sprintf (`{"Map":{%q:"foo"}}` , oid .Hex ()))
197
+ expectedData := mapOID {
198
+ Map : map [ObjectID ]string {oid : "foo" },
199
+ }
200
+
201
+ data := mapOID {}
202
+ err := json .Unmarshal (mapOIDJson , & data )
203
+ require .NoError (t , err )
204
+ require .Equal (t , expectedData , data )
205
+ }
175
206
func TestObjectID_UnmarshalJSON (t * testing.T ) {
176
207
oid := NewObjectID ()
177
208
@@ -189,6 +220,7 @@ func TestObjectID_UnmarshalJSON(t *testing.T) {
189
220
{"extended JSON" , extJSON , oid },
190
221
{"empty string" , emptyStringJSON , NilObjectID },
191
222
{"null" , nullJSON , NilObjectID },
223
+ {"map[ObjectID]string" , nullJSON , NilObjectID },
192
224
}
193
225
for _ , tc := range testCases {
194
226
t .Run (tc .name , func (t * testing.T ) {
0 commit comments