Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapters: Update to use jsonutil unmarshal #4021

Merged
merged 9 commits into from
Oct 30, 2024
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type TtxAdapter struct {
Expand Down Expand Up @@ -76,7 +77,7 @@ func (a *TtxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapter
// Skip over imps whose extensions cannot be read since
// we cannot glean Prod or ZoneID which are required to
// group together. However let's not block request creation.
if err := json.Unmarshal(impCopy.Ext, &impExt); err == nil {
if err := jsonutil.Unmarshal(impCopy.Ext, &impExt); err == nil {
impKey := impExt.Ttx.Prod + impExt.Ttx.Zoneid
groupedImps[impKey] = append(groupedImps[impKey], impCopy)
} else {
Expand Down Expand Up @@ -126,14 +127,14 @@ func makeImps(imp openrtb2.Imp) (openrtb2.Imp, error) {
}

var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
}

var ttxExt openrtb_ext.ExtImp33across
if err := json.Unmarshal(bidderExt.Bidder, &ttxExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &ttxExt); err != nil {
return openrtb2.Imp{}, &errortypes.BadInput{
Message: err.Error(),
}
Expand Down Expand Up @@ -177,7 +178,7 @@ func makeReqExt(request *openrtb2.BidRequest) ([]byte, error) {
var reqExt reqExt

if len(request.Ext) > 0 {
if err := json.Unmarshal(request.Ext, &reqExt); err != nil {
if err := jsonutil.Unmarshal(request.Ext, &reqExt); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -215,7 +216,7 @@ func (a *TtxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequ

var bidResp openrtb2.BidResponse

if err := json.Unmarshal(response.Body, &bidResp); err != nil {
if err := jsonutil.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}

Expand All @@ -226,7 +227,7 @@ func (a *TtxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequ
var bidExt bidExt
var bidType openrtb_ext.BidType

if err := json.Unmarshal(sb.Bid[i].Ext, &bidExt); err != nil {
if err := jsonutil.Unmarshal(sb.Bid[i].Ext, &bidExt); err != nil {
bidType = openrtb_ext.BidTypeBanner
} else {
bidType = getBidType(bidExt)
Expand Down
5 changes: 3 additions & 2 deletions adapters/aax/aax.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type adapter struct {
Expand Down Expand Up @@ -63,7 +64,7 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest

var bidResp openrtb2.BidResponse

if err := json.Unmarshal(response.Body, &bidResp); err != nil {
if err := jsonutil.Unmarshal(response.Body, &bidResp); err != nil {
return nil, []error{err}
}

Expand Down Expand Up @@ -96,7 +97,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co

func getMediaTypeForImp(bid openrtb2.Bid, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
var bidExt aaxResponseBidExt
err := json.Unmarshal(bid.Ext, &bidExt)
err := jsonutil.Unmarshal(bid.Ext, &bidExt)
if err == nil {
switch bidExt.AdCodeType {
case "banner":
Expand Down
7 changes: 4 additions & 3 deletions adapters/aceex/aceex.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type adapter struct {
Expand Down Expand Up @@ -90,13 +91,13 @@ func (a *adapter) MakeRequests(

func (a *adapter) getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtAceex, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
}
var aceexExt openrtb_ext.ExtAceex
if err := json.Unmarshal(bidderExt.Bidder, &aceexExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &aceexExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
Expand Down Expand Up @@ -151,7 +152,7 @@ func (a *adapter) MakeBids(

responseBody := bidderRawResponse.Body
var bidResp openrtb2.BidResponse
if err := json.Unmarshal(responseBody, &bidResp); err != nil {
if err := jsonutil.Unmarshal(responseBody, &bidResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: "Bad Server Response",
}}
Expand Down
7 changes: 4 additions & 3 deletions adapters/acuityads/acuityads.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type AcuityAdsAdapter struct {
Expand Down Expand Up @@ -90,13 +91,13 @@ func (a *AcuityAdsAdapter) MakeRequests(

func (a *AcuityAdsAdapter) getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtAcuityAds, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
}
var acuityAdsExt openrtb_ext.ExtAcuityAds
if err := json.Unmarshal(bidderExt.Bidder, &acuityAdsExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &acuityAdsExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
Expand Down Expand Up @@ -155,7 +156,7 @@ func (a *AcuityAdsAdapter) MakeBids(

responseBody := bidderRawResponse.Body
var bidResp openrtb2.BidResponse
if err := json.Unmarshal(responseBody, &bidResp); err != nil {
if err := jsonutil.Unmarshal(responseBody, &bidResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: "Bad Server Response",
}}
Expand Down
5 changes: 5 additions & 0 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -273,6 +274,10 @@ func assertErrorList(t *testing.T, description string, actual []error, expected
if matched, _ := regexp.MatchString(expected[i].Value, actual[i].Error()); !matched {
t.Errorf(`%s error[%d] had wrong message. Expected match with regex "%s", got "%s"`, description, i, expected[i].Value, actual[i].Error())
}
} else if expected[i].Comparison == "startswith" {
if !strings.HasPrefix(actual[i].Error(), expected[i].Value) {
t.Errorf(`%s error[%d] had wrong message. Expected to start with "%s", got "%s"`, description, i, expected[i].Value, actual[i].Error())
}
} else {
t.Fatalf(`invalid comparison type "%s"`, expected[i].Comparison)
}
Expand Down
7 changes: 4 additions & 3 deletions adapters/adelement/adelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type adapter struct {
Expand Down Expand Up @@ -58,13 +59,13 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

func getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ExtAdelement, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
}
var adelementExt openrtb_ext.ExtAdelement
if err := json.Unmarshal(bidderExt.Bidder, &adelementExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &adelementExt); err != nil {
return nil, &errortypes.BadInput{
Message: "ext.bidder not provided",
}
Expand All @@ -88,7 +89,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}

var response openrtb2.BidResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: "Bad Server Response",
}}
Expand Down
11 changes: 6 additions & 5 deletions adapters/adf/adf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type adapter struct {
Expand All @@ -36,15 +37,15 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

for _, imp := range request.Imp {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
errors = append(errors, &errortypes.BadInput{
Message: err.Error(),
})
continue
}

var adfImpExt openrtb_ext.ExtImpAdf
if err := json.Unmarshal(bidderExt.Bidder, &adfImpExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &adfImpExt); err != nil {
errors = append(errors, &errortypes.BadInput{
Message: err.Error(),
})
Expand All @@ -65,7 +66,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
var err error

if len(request.Ext) > 0 {
if err = json.Unmarshal(request.Ext, &requestExt); err != nil {
if err = jsonutil.Unmarshal(request.Ext, &requestExt); err != nil {
errors = append(errors, err)
}
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}

var response openrtb2.BidResponse
if err := json.Unmarshal(responseData.Body, &response); err != nil {
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

Expand All @@ -144,7 +145,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
if bid.Ext != nil {
var bidExt openrtb_ext.ExtBid
err := json.Unmarshal(bid.Ext, &bidExt)
err := jsonutil.Unmarshal(bid.Ext, &bidExt)
if err == nil && bidExt.Prebid != nil {
return openrtb_ext.ParseBidType(string(bidExt.Prebid.Type))
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/adf/adftest/supplemental/unparsable-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"expectedBidResponses": [],
"expectedMakeBidsErrors": [
{
"value": "json: cannot unmarshal string into Go value of type openrtb2.BidResponse",
"value": "expect { or n, but found \"",
"comparison": "literal"
}
]
Expand Down
8 changes: 4 additions & 4 deletions adapters/adgeneration/adgeneration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package adgeneration

import (
"encoding/json"
"errors"
"fmt"
"net/http"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type AdgenerationAdapter struct {
Expand Down Expand Up @@ -149,10 +149,10 @@ func (adg *AdgenerationAdapter) getRawQuery(id string, request *openrtb2.BidRequ
func unmarshalExtImpAdgeneration(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAdgeneration, error) {
var bidderExt adapters.ExtImpBidder
var adgExt openrtb_ext.ExtImpAdgeneration
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, err
}
if err := json.Unmarshal(bidderExt.Bidder, &adgExt); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &adgExt); err != nil {
return nil, err
}
if adgExt.Id == "" {
Expand Down Expand Up @@ -203,7 +203,7 @@ func (adg *AdgenerationAdapter) MakeBids(internalRequest *openrtb2.BidRequest, e
}}
}
var bidResp adgServerResponse
err := json.Unmarshal(response.Body, &bidResp)
err := jsonutil.Unmarshal(response.Body, &bidResp)
if err != nil {
return nil, []error{err}
}
Expand Down
15 changes: 8 additions & 7 deletions adapters/adhese/adhese.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/jsonutil"
)

type AdheseAdapter struct {
Expand All @@ -32,7 +33,7 @@ func extractTargetParameters(parameters openrtb_ext.ExtImpAdhese) string {
}
var parametersAsString = ""
var targetParsed map[string]interface{}
err := json.Unmarshal(parameters.Keywords, &targetParsed)
err := jsonutil.Unmarshal(parameters.Keywords, &targetParsed)
if err != nil {
return ""
}
Expand All @@ -59,7 +60,7 @@ func extractTargetParameters(parameters openrtb_ext.ExtImpAdhese) string {
func extractGdprParameter(request *openrtb2.BidRequest) string {
if request.User != nil {
var extUser openrtb_ext.ExtUser
if err := json.Unmarshal(request.User.Ext, &extUser); err == nil {
if err := jsonutil.Unmarshal(request.User.Ext, &extUser); err == nil {
return "/xt" + extUser.Consent
}
}
Expand Down Expand Up @@ -94,13 +95,13 @@ func (a *AdheseAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adap
var imp = &request.Imp[0]
var bidderExt adapters.ExtImpBidder

if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
errs = append(errs, WrapReqError("Request could not be parsed as ExtImpBidder due to: "+err.Error()))
return nil, errs
}

var params openrtb_ext.ExtImpAdhese
if err := json.Unmarshal(bidderExt.Bidder, &params); err != nil {
if err := jsonutil.Unmarshal(bidderExt.Bidder, &params); err != nil {
errs = append(errs, WrapReqError("Request could not be parsed as ExtImpAdhese due to: "+err.Error()))
return nil, errs
}
Expand Down Expand Up @@ -138,7 +139,7 @@ func (a *AdheseAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR
var bidResponse openrtb2.BidResponse

var adheseBidResponseArray []AdheseBid
if err := json.Unmarshal(response.Body, &adheseBidResponseArray); err != nil {
if err := jsonutil.Unmarshal(response.Body, &adheseBidResponseArray); err != nil {
return nil, []error{err, WrapServerError(fmt.Sprintf("Response %v could not be parsed as generic Adhese bid.", string(response.Body)))}
}

Expand All @@ -150,11 +151,11 @@ func (a *AdheseAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR
if adheseBid.Origin == "JERLICIA" {
var extArray []AdheseExt
var originDataArray []AdheseOriginData
if err := json.Unmarshal(response.Body, &extArray); err != nil {
if err := jsonutil.Unmarshal(response.Body, &extArray); err != nil {
return nil, []error{err, WrapServerError(fmt.Sprintf("Response %v could not be parsed to JERLICIA ext.", string(response.Body)))}
}

if err := json.Unmarshal(response.Body, &originDataArray); err != nil {
if err := jsonutil.Unmarshal(response.Body, &originDataArray); err != nil {
return nil, []error{err, WrapServerError(fmt.Sprintf("Response %v could not be parsed to JERLICIA origin data.", string(response.Body)))}
}
bidResponse = convertAdheseBid(adheseBid, extArray[0], originDataArray[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"expectedBidResponses": [],
"expectedMakeRequestsErrors": [
{
"value": "Request could not be parsed as ExtImpAdhese due to: unexpected end of JSON input",
"comparison": "literal"
"value": "Request could not be parsed as ExtImpAdhese due to: expect { or n, but found",
"comparison": "startswith"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"expectedBidResponses": [],
"expectedMakeRequestsErrors": [
{
"value": "Request could not be parsed as ExtImpBidder due to: unexpected end of JSON input",
"comparison": "literal"
"value": "Request could not be parsed as ExtImpBidder due to: expect { or n, but found",
"comparison": "startswith"
}
]
}
Loading
Loading