@@ -276,46 +276,32 @@ func modifyRequestWithStaticData(request *openrtb2.BidRequest) {
276
276
277
277
// change data type of user.ext.consented_providers_settings.consented_providers from []string to []int
278
278
if request .User != nil && request .User .Ext != nil {
279
- var userExt map [string ]interface {}
280
- var err error
281
-
282
- err = jsoniterator .Unmarshal (request .User .Ext , & userExt )
283
- if err != nil {
284
- return
285
- }
286
-
287
- providerSettings , ok := userExt ["consented_providers_settings" ].(map [string ]interface {})
288
- if ! ok {
289
- return
290
- }
291
-
292
- consentedProviders , ok := providerSettings ["consented_providers" ].([]interface {})
293
- if ! ok {
279
+ consentedProvidedBytes , dataType , _ , err := jsonparser .Get (request .User .Ext , "consented_providers_settings" , "consented_providers" )
280
+ if err != nil || dataType != jsonparser .Array {
294
281
return
295
282
}
296
283
297
- var consentedProvidersInt []int
298
- for i := range consentedProviders {
299
- provider , ok := consentedProviders [i ].(string )
300
- if ! ok {
301
- continue
284
+ var consentedProviders []int
285
+ _ , err = jsonparser .ArrayEach (consentedProvidedBytes , func (provider []byte , dataType jsonparser.ValueType , offset int , err error ) {
286
+ if err != nil || dataType != jsonparser .String {
287
+ return
302
288
}
303
289
304
- providerInt , err := strconv .Atoi (provider )
305
- if err ! = nil {
306
- continue
290
+ providerInt , err := strconv .Atoi (string ( provider ) )
291
+ if err = = nil {
292
+ consentedProviders = append ( consentedProviders , providerInt )
307
293
}
308
-
309
- consentedProvidersInt = append (consentedProvidersInt , providerInt )
294
+ })
295
+ if err != nil {
296
+ return
310
297
}
311
298
312
- providerSettings ["consented_providers" ] = consentedProvidersInt
313
- userExt ["consented_providers_settings" ] = providerSettings
314
-
315
- request .User .Ext , err = jsoniterator .Marshal (userExt )
299
+ providesBytes , err := jsoniterator .Marshal (consentedProviders )
316
300
if err != nil {
317
- glog .Errorf ("[GoogleSDK] [Error]: failed to marshal user ext %v" , err )
301
+ glog .Errorf ("[GoogleSDK] [Error]: failed to marshal consented providers %v" , err )
318
302
}
303
+
304
+ request .User .Ext , _ = jsonparser .Set (request .User .Ext , providesBytes , "consented_providers_settings" , "consented_providers" )
319
305
}
320
306
}
321
307
0 commit comments