diff --git a/go.mod b/go.mod index 2d8f751..ab16313 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.12 require ( github.com/go-test/deep v1.0.4 + github.com/google/go-cmp v0.5.6 github.com/mailru/easyjson v0.7.7 golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect ) diff --git a/go.sum b/go.sum index 5935c4c..f40338a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,11 @@ github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho= github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8= +github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -18,3 +24,4 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/openrtb/application.go b/openrtb/application.go index d156a64..9bf7739 100644 --- a/openrtb/application.go +++ b/openrtb/application.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Application object should be included if the ad supported content is a // non-browser application (typically in mobile) as opposed to a website. @@ -134,7 +138,7 @@ type Application struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Application object contains required and well-formatted data @@ -171,7 +175,7 @@ func (a *Application) Copy() *Application { appCopy.Publisher = a.Publisher.Copy() appCopy.Content = a.Content.Copy() - appCopy.Extension = util.DeepCopyCopiable(a.Extension) + appCopy.Extension = util.DeepCopyJSONRawMsg(a.Extension) return &appCopy } diff --git a/openrtb/application_easyjson.go b/openrtb/application_easyjson.go index adf7dcf..8a5cd6b 100644 --- a/openrtb/application_easyjson.go +++ b/openrtb/application_easyjson.go @@ -148,12 +148,8 @@ func easyjsonB2e97d60DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Ap case "keywords": out.Keywords = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -332,7 +328,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in A } out.String(string(in.Keywords)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -340,13 +336,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in A } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -548,12 +538,8 @@ func easyjsonB2e97d60DecodeGithubComVungleVungoOpenrtb2(in *jlexer.Lexer, out *C in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -837,7 +823,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -845,13 +831,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -910,12 +890,8 @@ func easyjsonB2e97d60DecodeGithubComVungleVungoOpenrtb4(in *jlexer.Lexer, out *D in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -970,7 +946,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb4(out *jwriter.Writer, in out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -978,13 +954,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb4(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -1014,12 +984,8 @@ func easyjsonB2e97d60DecodeGithubComVungleVungoOpenrtb5(in *jlexer.Lexer, out *S case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1061,7 +1027,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb5(out *jwriter.Writer, in } out.String(string(in.Value)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1069,13 +1035,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb5(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -1128,12 +1088,8 @@ func easyjsonB2e97d60DecodeGithubComVungleVungoOpenrtb3(in *jlexer.Lexer, out *P case "domain": out.Domain = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1194,7 +1150,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } out.String(string(in.Domain)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1202,13 +1158,7 @@ func easyjsonB2e97d60EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/audio.go b/openrtb/audio.go index cc39a5e..14a88d8 100644 --- a/openrtb/audio.go +++ b/openrtb/audio.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -185,7 +186,7 @@ type Audio struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -249,7 +250,7 @@ func (a *Audio) Copy() *Audio { copy(vCopy.CompanionTypes, a.CompanionTypes) } - vCopy.Extension = util.DeepCopyCopiable(a.Extension) + vCopy.Extension = util.DeepCopyJSONRawMsg(a.Extension) return &vCopy } diff --git a/openrtb/audio_easyjson.go b/openrtb/audio_easyjson.go index bfbe854..b2b7b1c 100644 --- a/openrtb/audio_easyjson.go +++ b/openrtb/audio_easyjson.go @@ -246,12 +246,8 @@ func easyjson48f1e884DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Au case "nvol": out.NormalizedVolume = VolumeNormalizationMode(in.Int()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -422,16 +418,10 @@ func easyjson48f1e884EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in A out.RawString(prefix) out.Int(int(in.NormalizedVolume)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -685,12 +675,8 @@ func easyjson48f1e884DecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *B case "vcm": out.VCM = CompanionRenderingMode(in.Int()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -916,7 +902,7 @@ func easyjson48f1e884EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } out.Int(int(in.VCM)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -924,13 +910,7 @@ func easyjson48f1e884EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -964,12 +944,8 @@ func easyjson48f1e884DecodeGithubComVungleVungoOpenrtb2(in *jlexer.Lexer, out *F case "wmin": out.WMin = uint64(in.Uint64()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1031,7 +1007,7 @@ func easyjson48f1e884EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } out.Uint64(uint64(in.WMin)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1039,13 +1015,7 @@ func easyjson48f1e884EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/banner.go b/openrtb/banner.go index aeacca2..c62ebd1 100644 --- a/openrtb/banner.go +++ b/openrtb/banner.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -179,7 +180,7 @@ type Banner struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -213,10 +214,12 @@ func (v *Banner) Copy() *Banner { if v.Format != nil { vCopy.Format = make([]Format, len(v.Format)) - copy(vCopy.Format, v.Format) + for i, format := range v.Format { + vCopy.Format[i] = *format.Copy() + } } - vCopy.Extension = util.DeepCopyCopiable(v.Extension) + vCopy.Extension = util.DeepCopyJSONRawMsg(v.Extension) return &vCopy } diff --git a/openrtb/banner_easyjson.go b/openrtb/banner_easyjson.go index e474fa1..31489ce 100644 --- a/openrtb/banner_easyjson.go +++ b/openrtb/banner_easyjson.go @@ -243,12 +243,8 @@ func easyjsonC16456caDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Ba case "vcm": out.VCM = CompanionRenderingMode(in.Int()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -474,7 +470,7 @@ func easyjsonC16456caEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in B } out.Int(int(in.VCM)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -482,13 +478,7 @@ func easyjsonC16456caEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in B } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -546,12 +536,8 @@ func easyjsonC16456caDecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *F case "wmin": out.WMin = uint64(in.Uint64()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -613,7 +599,7 @@ func easyjsonC16456caEncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } out.Uint64(uint64(in.WMin)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -621,13 +607,7 @@ func easyjsonC16456caEncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/bidrequest.go b/openrtb/bidrequest.go index 089a782..275df28 100644 --- a/openrtb/bidrequest.go +++ b/openrtb/bidrequest.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "fmt" "github.com/Vungle/vungo/internal/util" @@ -218,7 +219,7 @@ type BidRequest struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the BidRequest object contains required and well-formatted data @@ -285,6 +286,6 @@ func (r *BidRequest) Copy() *BidRequest { brCopy.BlockedAdvertisersByMarketID = util.DeepCopyStrSlice(r.BlockedAdvertisersByMarketID) brCopy.Regulation = r.Regulation.Copy() brCopy.Source = r.Source.Copy() - brCopy.Extension = util.DeepCopyCopiable(r.Extension) + brCopy.Extension = util.DeepCopyJSONRawMsg(r.Extension) return &brCopy } diff --git a/openrtb/bidrequest_easyjson.go b/openrtb/bidrequest_easyjson.go index 92d4c22..3ad1002 100644 --- a/openrtb/bidrequest_easyjson.go +++ b/openrtb/bidrequest_easyjson.go @@ -303,12 +303,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Bi easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb6(in, out.Regulation) } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -497,16 +493,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in B out.RawString(prefix) easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb6(out, *in.Regulation) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -566,12 +556,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb6(in *jlexer.Lexer, out *R } } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -593,7 +579,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb6(out *jwriter.Writer, in out.RawString(prefix[1:]) out.Raw((*in.IsCoppaCompliant).MarshalJSON()) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -601,13 +587,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb6(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -637,12 +617,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb5(in *jlexer.Lexer, out *S case "pchain": out.PChain = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -684,7 +660,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb5(out *jwriter.Writer, in } out.String(string(in.PChain)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -692,13 +668,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb5(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -767,12 +737,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb4(in *jlexer.Lexer, out *U in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -873,7 +839,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb4(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -881,13 +847,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb4(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -946,12 +906,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb8(in *jlexer.Lexer, out *D in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1006,7 +962,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb8(out *jwriter.Writer, in out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1014,13 +970,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb8(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -1050,12 +1000,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb9(in *jlexer.Lexer, out *S case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1097,7 +1043,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb9(out *jwriter.Writer, in } out.String(string(in.Value)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1105,13 +1051,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb9(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -1161,12 +1101,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb7(in *jlexer.Lexer, out *G case "utcoffset": out.UTCOffset = int(in.Int()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1308,7 +1244,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb7(out *jwriter.Writer, in } out.Int(int(in.UTCOffset)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1316,13 +1252,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb7(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -1456,12 +1386,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb3(in *jlexer.Lexer, out *D case "macmd5": out.MACMD5 = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1773,7 +1699,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } out.String(string(in.MACMD5)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -1781,13 +1707,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -1938,12 +1858,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb2(in *jlexer.Lexer, out *S case "keywords": out.Keywords = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -2122,7 +2038,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } out.String(string(in.Keywords)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -2130,13 +2046,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -2314,12 +2224,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb11(in *jlexer.Lexer, out * in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -2603,7 +2509,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb11(out *jwriter.Writer, in out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -2611,13 +2517,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb11(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -2670,12 +2570,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb12(in *jlexer.Lexer, out * case "domain": out.Domain = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -2736,7 +2632,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb12(out *jwriter.Writer, in } out.String(string(in.Domain)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -2744,13 +2640,7 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb12(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -3022,12 +2912,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *I case "exp": out.Exp = int(in.Int()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -3150,16 +3036,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in out.RawString(prefix) out.Int(int(in.Exp)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -3218,12 +3098,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb16(in *jlexer.Lexer, out * in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -3264,16 +3140,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb16(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -3351,12 +3221,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb17(in *jlexer.Lexer, out * in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -3420,16 +3286,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb17(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -3503,12 +3363,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb15(in *jlexer.Lexer, out * in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -3562,16 +3418,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb15(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -3841,12 +3691,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb14(in *jlexer.Lexer, out * in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -4066,16 +3912,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb14(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -4105,12 +3945,8 @@ func easyjson89fe9b30DecodeGithubComVungleVungoOpenrtb13(in *jlexer.Lexer, out * case "vendor": out.Vendor = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -4141,16 +3977,10 @@ func easyjson89fe9b30EncodeGithubComVungleVungoOpenrtb13(out *jwriter.Writer, in out.RawString(prefix) out.String(string(in.Vendor)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/bidresponse.go b/openrtb/bidresponse.go index b4f59d8..7018d1b 100644 --- a/openrtb/bidresponse.go +++ b/openrtb/bidresponse.go @@ -16,15 +16,13 @@ var emptyBid BidResponse //go:generate easyjson $GOFILE //easyjson:json type BidResponse struct { - ID string `json:"id"` - SeatBids []*SeatBid `json:"seatbid,omitempty"` - BidID string `json:"bidid,omitempty"` - Currency Currency `json:"cur,omitempty"` - CustomData string `json:"customdata,omitempty"` - NoBidReason *NoBidReason `json:"nbr,omitempty"` - - RawExtension json.RawMessage `json:"ext,omitempty"` - Extension interface{} `json:"-"` // Opaque value that can be used to store unmarshaled value in ext field. + ID string `json:"id"` + SeatBids []*SeatBid `json:"seatbid,omitempty"` + BidID string `json:"bidid,omitempty"` + Currency Currency `json:"cur,omitempty"` + CustomData string `json:"customdata,omitempty"` + NoBidReason *NoBidReason `json:"nbr,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method validates whether the BidResponse object contains valid data, or returns an @@ -86,7 +84,7 @@ func (r *BidResponse) Copy() *BidResponse { } if r.Extension != nil { - brCopy.RawExtension = util.DeepCopyJSONRawMsg(r.RawExtension) + brCopy.Extension = util.DeepCopyJSONRawMsg(r.Extension) } return &brCopy diff --git a/openrtb/bidresponse_easyjson.go b/openrtb/bidresponse_easyjson.go index ac37151..d54c457 100644 --- a/openrtb/bidresponse_easyjson.go +++ b/openrtb/bidresponse_easyjson.go @@ -87,7 +87,7 @@ func easyjson10eb023eDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Bi } case "ext": if data := in.Raw(); in.Ok() { - in.AddError((out.RawExtension).UnmarshalJSON(data)) + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -146,10 +146,10 @@ func easyjson10eb023eEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in B out.RawString(prefix) out.Int(int(*in.NoBidReason)) } - if len(in.RawExtension) != 0 { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - out.Raw((in.RawExtension).MarshalJSON()) + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/bidresponse_test.go b/openrtb/bidresponse_test.go index 3143e3b..886debc 100644 --- a/openrtb/bidresponse_test.go +++ b/openrtb/bidresponse_test.go @@ -111,9 +111,7 @@ func TestBidResponse_Copy(t *testing.T) { } openrtbtest.FillWithNonNilValue(&bidResponse) - bidResponse.Extension = true // hack to workaround BidResponse specific Copy implementation about RawExtension respCopy := bidResponse.Copy() - respCopy.Extension = true if err := openrtbtest.VerifyDeepCopy( &bidResponse, respCopy); err != nil { t.Errorf("Copy() should be deep copy\n%v\n", err) diff --git a/openrtb/content.go b/openrtb/content.go index e0ba44a..4c0fc08 100644 --- a/openrtb/content.go +++ b/openrtb/content.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Content object describes the content in which the impression will appear, // which may be syndicated or nonsyndicated content. @@ -237,7 +241,7 @@ type Content struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Site object contains required and @@ -267,6 +271,6 @@ func (c *Content) Copy() *Content { cCopy.Data[i] = c.Data[i].Copy() } } - cCopy.Ext = util.DeepCopyCopiable(c.Ext) + cCopy.Ext = util.DeepCopyJSONRawMsg(c.Ext) return &cCopy } diff --git a/openrtb/content_easyjson.go b/openrtb/content_easyjson.go index dfa591d..50af3a3 100644 --- a/openrtb/content_easyjson.go +++ b/openrtb/content_easyjson.go @@ -191,12 +191,8 @@ func easyjson344736e9DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Co in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -480,7 +476,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in C out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -488,13 +484,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in C } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -577,12 +567,8 @@ func easyjson344736e9DecodeGithubComVungleVungoOpenrtb2(in *jlexer.Lexer, out *D in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -637,7 +623,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -645,13 +631,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -681,12 +661,8 @@ func easyjson344736e9DecodeGithubComVungleVungoOpenrtb3(in *jlexer.Lexer, out *S case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -728,7 +704,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } out.String(string(in.Value)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -736,13 +712,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -795,12 +765,8 @@ func easyjson344736e9DecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *P case "domain": out.Domain = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -861,7 +827,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } out.String(string(in.Domain)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -869,13 +835,7 @@ func easyjson344736e9EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/data.go b/openrtb/data.go index 3f7b27b..1f504c3 100644 --- a/openrtb/data.go +++ b/openrtb/data.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Data object // The data and segment objects together allow additional data about the related @@ -46,7 +50,7 @@ type Data struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Site object contains required and @@ -69,6 +73,6 @@ func (d *Data) Copy() *Data { dCopy.Segment[i] = d.Segment[i].Copy() } } - dCopy.Ext = util.DeepCopyCopiable(d.Ext) + dCopy.Ext = util.DeepCopyJSONRawMsg(d.Ext) return &dCopy } diff --git a/openrtb/data_easyjson.go b/openrtb/data_easyjson.go index c793b49..9789e8a 100644 --- a/openrtb/data_easyjson.go +++ b/openrtb/data_easyjson.go @@ -72,12 +72,8 @@ func easyjson794297d0DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Da in.Delim(']') } case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -132,7 +128,7 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in D out.RawByte(']') } } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -140,13 +136,7 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in D } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } @@ -200,12 +190,8 @@ func easyjson794297d0DecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *S case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -247,7 +233,7 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } out.String(string(in.Value)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -255,13 +241,7 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/deal.go b/openrtb/deal.go index 9c53356..aa9be5a 100644 --- a/openrtb/deal.go +++ b/openrtb/deal.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -75,7 +76,7 @@ type Deal struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -97,7 +98,7 @@ func (d *Deal) Copy() *Deal { dealCopy := *d dealCopy.WhitelistedSeats = util.DeepCopyStrSlice(d.WhitelistedSeats) dealCopy.AdvertiserDomains = util.DeepCopyStrSlice(d.AdvertiserDomains) - dealCopy.Extension = util.DeepCopyCopiable(d.Extension) + dealCopy.Extension = util.DeepCopyJSONRawMsg(d.Extension) return &dealCopy } diff --git a/openrtb/deal_easyjson.go b/openrtb/deal_easyjson.go index 8e46a2f..0ffecc2 100644 --- a/openrtb/deal_easyjson.go +++ b/openrtb/deal_easyjson.go @@ -91,12 +91,8 @@ func easyjson8a221a72DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *De in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -160,16 +156,10 @@ func easyjson8a221a72EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in D out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/device.go b/openrtb/device.go index 5b8e042..9d396ac 100644 --- a/openrtb/device.go +++ b/openrtb/device.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Device object provides information pertaining to the device through which the // user is interacting. @@ -267,7 +271,7 @@ type Device struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Copy do deep copy of Device. @@ -280,7 +284,7 @@ func (d *Device) Copy() *Device { deviceCopy := *d if d.Geo != nil { - geoCopy := *d.Geo + geoCopy := *d.Geo.Copy() deviceCopy.Geo = &geoCopy } @@ -299,7 +303,7 @@ func (d *Device) Copy() *Device { deviceCopy.SupportsJavaScript = &SupportsJavaScriptCopy } deviceCopy.GeoFetch = d.GeoFetch.Copy() - deviceCopy.Extension = util.DeepCopyCopiable(d.Extension) + deviceCopy.Extension = util.DeepCopyJSONRawMsg(d.Extension) return &deviceCopy } diff --git a/openrtb/device_easyjson.go b/openrtb/device_easyjson.go index 5890a2e..9010484 100644 --- a/openrtb/device_easyjson.go +++ b/openrtb/device_easyjson.go @@ -147,12 +147,8 @@ func easyjson3073ac56DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *De case "macmd5": out.MACMD5 = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -464,7 +460,7 @@ func easyjson3073ac56EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in D } out.String(string(in.MACMD5)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -472,13 +468,7 @@ func easyjson3073ac56EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in D } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -552,12 +542,8 @@ func easyjson3073ac56DecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *G case "utcoffset": out.UTCOffset = int(in.Int()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -699,7 +685,7 @@ func easyjson3073ac56EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } out.Int(int(in.UTCOffset)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -707,13 +693,7 @@ func easyjson3073ac56EncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/format.go b/openrtb/format.go index c96206d..71aa62f 100644 --- a/openrtb/format.go +++ b/openrtb/format.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Format object represents an allowed size (i.e., height and width combination) or Flex Ad parameters for a banner impression. // These are typically used in an array where multiple sizes are permitted. @@ -56,7 +60,7 @@ type Format struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Copy do deep copy of Format. @@ -67,6 +71,6 @@ func (f *Format) Copy() *Format { return nil } fCopy := *f - fCopy.Ext = util.DeepCopyCopiable(f.Ext) + fCopy.Ext = util.DeepCopyJSONRawMsg(f.Ext) return &fCopy } diff --git a/openrtb/format_easyjson.go b/openrtb/format_easyjson.go index dee5a47..b57c766 100644 --- a/openrtb/format_easyjson.go +++ b/openrtb/format_easyjson.go @@ -47,12 +47,8 @@ func easyjson72863a49DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Fo case "wmin": out.WMin = uint64(in.Uint64()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -114,7 +110,7 @@ func easyjson72863a49EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in F } out.Uint64(uint64(in.WMin)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -122,13 +118,7 @@ func easyjson72863a49EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in F } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/geo.go b/openrtb/geo.go index 27dcd10..520833a 100644 --- a/openrtb/geo.go +++ b/openrtb/geo.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Geo object encapsulates various methods for specifying a geographic location. // When subordinate to a Device object, it indicates the location of the device @@ -138,7 +142,7 @@ type Geo struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Copy do deep copy of Geo. @@ -149,6 +153,6 @@ func (g *Geo) Copy() *Geo { return nil } gCopy := *g - gCopy.Ext = util.DeepCopyCopiable(g.Ext) + gCopy.Ext = util.DeepCopyJSONRawMsg(g.Ext) return &gCopy } diff --git a/openrtb/geo_easyjson.go b/openrtb/geo_easyjson.go index 076a32e..43a035c 100644 --- a/openrtb/geo_easyjson.go +++ b/openrtb/geo_easyjson.go @@ -63,12 +63,8 @@ func easyjsonA0535929DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Ge case "utcoffset": out.UTCOffset = int(in.Int()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -210,7 +206,7 @@ func easyjsonA0535929EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in G } out.Int(int(in.UTCOffset)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -218,13 +214,7 @@ func easyjsonA0535929EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in G } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/impression.go b/openrtb/impression.go index 092bdc7..fa6b4ab 100644 --- a/openrtb/impression.go +++ b/openrtb/impression.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Impression object describes an ad placement or impression being auctioned. // A single bid request can include multiple Imp objects, a use case for which @@ -184,7 +188,7 @@ type Impression struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Copy returns a pointer to a copy of the Impression object. @@ -210,7 +214,7 @@ func (imp *Impression) Copy() *Impression { } impressionCopy.IframeBuster = util.DeepCopyStrSlice(imp.IframeBuster) - impressionCopy.Extension = util.DeepCopyCopiable(imp.Extension) + impressionCopy.Extension = util.DeepCopyJSONRawMsg(imp.Extension) return &impressionCopy } diff --git a/openrtb/impression_easyjson.go b/openrtb/impression_easyjson.go index 1439d04..482d2fb 100644 --- a/openrtb/impression_easyjson.go +++ b/openrtb/impression_easyjson.go @@ -173,12 +173,8 @@ func easyjson7ebaa60bDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Im case "exp": out.Exp = int(in.Int()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -301,16 +297,10 @@ func easyjson7ebaa60bEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in I out.RawString(prefix) out.Int(int(in.Exp)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -393,12 +383,8 @@ func easyjson7ebaa60bDecodeGithubComVungleVungoOpenrtb4(in *jlexer.Lexer, out *P in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -439,16 +425,10 @@ func easyjson7ebaa60bEncodeGithubComVungleVungoOpenrtb4(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -522,12 +502,8 @@ func easyjson7ebaa60bDecodeGithubComVungleVungoOpenrtb3(in *jlexer.Lexer, out *N in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -581,16 +557,10 @@ func easyjson7ebaa60bEncodeGithubComVungleVungoOpenrtb3(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -860,12 +830,8 @@ func easyjson7ebaa60bDecodeGithubComVungleVungoOpenrtb2(in *jlexer.Lexer, out *V in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1085,16 +1051,10 @@ func easyjson7ebaa60bEncodeGithubComVungleVungoOpenrtb2(out *jwriter.Writer, in out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -1124,12 +1084,8 @@ func easyjson7ebaa60bDecodeGithubComVungleVungoOpenrtb1(in *jlexer.Lexer, out *M case "vendor": out.Vendor = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -1160,16 +1116,10 @@ func easyjson7ebaa60bEncodeGithubComVungleVungoOpenrtb1(out *jwriter.Writer, in out.RawString(prefix) out.String(string(in.Vendor)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/metric.go b/openrtb/metric.go index e4d73af..f887130 100644 --- a/openrtb/metric.go +++ b/openrtb/metric.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -46,7 +47,7 @@ type Metric struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -67,6 +68,6 @@ func (m *Metric) Copy() *Metric { return nil } mCopy := *m - mCopy.Ext = util.DeepCopyCopiable(m.Ext) + mCopy.Ext = util.DeepCopyJSONRawMsg(m.Ext) return &mCopy } diff --git a/openrtb/metric_easyjson.go b/openrtb/metric_easyjson.go index 6e7d4f1..9abe315 100644 --- a/openrtb/metric_easyjson.go +++ b/openrtb/metric_easyjson.go @@ -43,12 +43,8 @@ func easyjson9478868cDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Me case "vendor": out.Vendor = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -79,16 +75,10 @@ func easyjson9478868cEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in M out.RawString(prefix) out.String(string(in.Vendor)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/metric_test.go b/openrtb/metric_test.go index 606fbf6..06bf0aa 100644 --- a/openrtb/metric_test.go +++ b/openrtb/metric_test.go @@ -1,6 +1,7 @@ package openrtb_test import ( + "encoding/json" "testing" "github.com/Vungle/vungo/openrtb" @@ -26,7 +27,7 @@ func TestMetric_Validate(t *testing.T) { Type string Value float64 Vendor string - Ext interface{} + Ext json.RawMessage } tests := []struct { name string diff --git a/openrtb/native.go b/openrtb/native.go index 06945e6..795190c 100644 --- a/openrtb/native.go +++ b/openrtb/native.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -62,7 +63,7 @@ type Native struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -93,7 +94,7 @@ func (n *Native) Copy() *Native { copy(vCopy.APIFrameworks, n.APIFrameworks) } - vCopy.Extension = util.DeepCopyCopiable(n.Extension) + vCopy.Extension = util.DeepCopyJSONRawMsg(n.Extension) return &vCopy } diff --git a/openrtb/native/request/asset.go b/openrtb/native/request/asset.go index 5899120..7212e6d 100644 --- a/openrtb/native/request/asset.go +++ b/openrtb/native/request/asset.go @@ -1,5 +1,7 @@ package request +import "encoding/json" + // Asset Object is the main container object for each asset requested or supported by Exchange on behalf of the rendering client. // Any object that is required is to be flagged as such. // Only one of the {title,img,video,data} objects should be present in each object. @@ -96,5 +98,5 @@ type Asset struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/asset_easyjson.go b/openrtb/native/request/asset_easyjson.go index a0274cf..8a7b2b1 100644 --- a/openrtb/native/request/asset_easyjson.go +++ b/openrtb/native/request/asset_easyjson.go @@ -83,12 +83,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest4(in, out.Data) } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -134,16 +130,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawString(prefix) easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest4(out, *in.Data) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -195,12 +185,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest4(in *jlexer. case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -226,16 +212,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest4(out *jwrite out.RawString(prefix) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -309,12 +289,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest3(in *jlexer. in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -372,16 +348,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest3(out *jwrite out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -438,12 +408,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest2(in *jlexer. in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -524,7 +490,7 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest2(out *jwrite out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -532,13 +498,7 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest2(out *jwrite } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -564,12 +524,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeRequest1(in *jlexer. case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -590,16 +546,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeRequest1(out *jwrite out.RawString(prefix[1:]) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/data.go b/openrtb/native/request/data.go index ac579b9..7daaa7d 100644 --- a/openrtb/native/request/data.go +++ b/openrtb/native/request/data.go @@ -1,6 +1,10 @@ package request -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // Data Object is to be used for all non-core elements of the native unit such as Brand Name, Ratings, Review Count, Stars, Download count, descriptions etc. // It is also generic for future native elements not contemplated at the time of the writing of this document. @@ -41,5 +45,5 @@ type Data struct { // object // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility beyond the standard defined in this specification - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/data_easyjson.go b/openrtb/native/request/data_easyjson.go index 733da9c..b1e99a6 100644 --- a/openrtb/native/request/data_easyjson.go +++ b/openrtb/native/request/data_easyjson.go @@ -42,12 +42,8 @@ func easyjson794297d0DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -73,16 +69,10 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawString(prefix) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/eventtracker.go b/openrtb/native/request/eventtracker.go index 72919c9..5a5b80f 100644 --- a/openrtb/native/request/eventtracker.go +++ b/openrtb/native/request/eventtracker.go @@ -1,6 +1,10 @@ package request -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // EventTracker object specifies the types of events the bidder can request to be tracked in the bid response, and which //types of tracking are available for each event type, and is included as an array in the request. @@ -39,5 +43,5 @@ type EventTracker struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/eventtracker_easyjson.go b/openrtb/native/request/eventtracker_easyjson.go index 86142c1..7de6992 100644 --- a/openrtb/native/request/eventtracker_easyjson.go +++ b/openrtb/native/request/eventtracker_easyjson.go @@ -63,12 +63,8 @@ func easyjson88abeb4cDecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -105,16 +101,10 @@ func easyjson88abeb4cEncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/image.go b/openrtb/native/request/image.go index 152935d..1633f08 100644 --- a/openrtb/native/request/image.go +++ b/openrtb/native/request/image.go @@ -1,6 +1,10 @@ package request -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // Image object to be used for all image elements of the Native ad such as Icons, Main Image, etc. // Recommended sizes and aspect ratios are included in the Image Asset Types section. @@ -93,5 +97,5 @@ type Image struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/image_easyjson.go b/openrtb/native/request/image_easyjson.go index 800d978..392af4f 100644 --- a/openrtb/native/request/image_easyjson.go +++ b/openrtb/native/request/image_easyjson.go @@ -71,12 +71,8 @@ func easyjson220accf5DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -157,7 +153,7 @@ func easyjson220accf5EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -165,13 +161,7 @@ func easyjson220accf5EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/request.go b/openrtb/native/request/request.go index 468e7e4..7fe34b9 100644 --- a/openrtb/native/request/request.go +++ b/openrtb/native/request/request.go @@ -1,6 +1,10 @@ package request -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // Request Object defines the native advertising opportunity available for bid via this bid // request. It will be included as a JSON-encoded string in the bid request’s imp.native field or as a @@ -156,5 +160,5 @@ type Request struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility beyond //the standard defined in this specification - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/request_easyjson.go b/openrtb/native/request/request_easyjson.go index ec126f7..63e7329 100644 --- a/openrtb/native/request/request_easyjson.go +++ b/openrtb/native/request/request_easyjson.go @@ -57,7 +57,7 @@ func easyjson3c9d2b01DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L in.Delim('[') if out.Assets == nil { if !in.IsDelim(']') { - out.Assets = make([]Asset, 0, 1) + out.Assets = make([]Asset, 0, 0) } else { out.Assets = []Asset{} } @@ -102,12 +102,8 @@ func easyjson3c9d2b01DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L case "privacy": out.Privacy = int8(in.Int8()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -229,16 +225,10 @@ func easyjson3c9d2b01EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawString(prefix) out.Int8(int8(in.Privacy)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/title.go b/openrtb/native/request/title.go index b1466d8..2af805f 100644 --- a/openrtb/native/request/title.go +++ b/openrtb/native/request/title.go @@ -1,5 +1,7 @@ package request +import "encoding/json" + // Title object is to be used for title element of the Native ad. // // See OpenRTB Native 1.2 Sec 4.3 Title Object @@ -26,5 +28,5 @@ type Title struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/title_easyjson.go b/openrtb/native/request/title_easyjson.go index a136b48..facfbf0 100644 --- a/openrtb/native/request/title_easyjson.go +++ b/openrtb/native/request/title_easyjson.go @@ -39,12 +39,8 @@ func easyjsonE7952480DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -65,16 +61,10 @@ func easyjsonE7952480EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawString(prefix[1:]) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/request/video.go b/openrtb/native/request/video.go index 7eff2cd..c64ae06 100644 --- a/openrtb/native/request/video.go +++ b/openrtb/native/request/video.go @@ -1,6 +1,10 @@ package request -import "github.com/Vungle/vungo/openrtb" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb" +) // Video object to be used for all video elements supported in the Native Ad. This corresponds to the Video object of // OpenRTB. Exchange implementers can impose their own specific restrictions. Here are the required attributes of the @@ -62,5 +66,5 @@ type Video struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility beyond // the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/request/video_easyjson.go b/openrtb/native/request/video_easyjson.go index f63348c..408a25d 100644 --- a/openrtb/native/request/video_easyjson.go +++ b/openrtb/native/request/video_easyjson.go @@ -88,12 +88,8 @@ func easyjson3c9ce8c3DecodeGithubComVungleVungoOpenrtbNativeRequest(in *jlexer.L in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -151,16 +147,10 @@ func easyjson3c9ce8c3EncodeGithubComVungleVungoOpenrtbNativeRequest(out *jwriter out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/asset.go b/openrtb/native/response/asset.go index ab0ce71..b666479 100644 --- a/openrtb/native/response/asset.go +++ b/openrtb/native/response/asset.go @@ -1,5 +1,7 @@ package response +import "encoding/json" + // Asset Object is the main container object for each asset requested or supported by Exchange on behalf of the // rendering client. Any object that is required is to be flagged as such. Only one of the {title,img,video,data} // objects should be present in each object. All others should be null/absent. The id is to be unique within the @@ -98,5 +100,5 @@ type Asset struct { // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. // Bidders are encouraged not to use asset.ext for exchanging text assets. Use data.ext with custom type instead. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/asset_easyjson.go b/openrtb/native/response/asset_easyjson.go index d742a63..13b45aa 100644 --- a/openrtb/native/response/asset_easyjson.go +++ b/openrtb/native/response/asset_easyjson.go @@ -92,12 +92,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse5(in, out.Link) } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -179,7 +175,7 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite } easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse5(out, *in.Link) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -187,13 +183,7 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -268,12 +258,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse5(in *jlexer case "fallback": out.Fallback = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -313,16 +299,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse5(out *jwrit out.RawString(prefix) out.String(string(in.Fallback)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -352,12 +332,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse4(in *jlexer case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -399,16 +375,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse4(out *jwrit } out.String(string(in.Value)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -482,12 +452,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse2(in *jlexer case "h": out.H = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -529,16 +495,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse2(out *jwrit out.RawString(prefix) out.Int64(int64(in.H)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } @@ -566,12 +526,8 @@ func easyjson3b94576aDecodeGithubComVungleVungoOpenrtbNativeResponse1(in *jlexer case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -597,16 +553,10 @@ func easyjson3b94576aEncodeGithubComVungleVungoOpenrtbNativeResponse1(out *jwrit out.RawString(prefix) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/data.go b/openrtb/native/response/data.go index 4238e74..de065e2 100644 --- a/openrtb/native/response/data.go +++ b/openrtb/native/response/data.go @@ -1,6 +1,10 @@ package response -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // Data corresponds to the Data Object in the request, with the value filled in. The Data Object is to be used for all // miscellaneous elements of the native unit such as Brand Name, Ratings, Review Count, Stars, Downloads, Price count @@ -53,5 +57,5 @@ type Data struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/data_easyjson.go b/openrtb/native/response/data_easyjson.go index ff3a764..c76d82f 100644 --- a/openrtb/native/response/data_easyjson.go +++ b/openrtb/native/response/data_easyjson.go @@ -44,12 +44,8 @@ func easyjson794297d0DecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -91,16 +87,10 @@ func easyjson794297d0EncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite } out.String(string(in.Value)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/eventtracker.go b/openrtb/native/response/eventtracker.go index adabd10..10bb3b2 100644 --- a/openrtb/native/response/eventtracker.go +++ b/openrtb/native/response/eventtracker.go @@ -65,5 +65,5 @@ type EventTracker struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/eventtracker_easyjson.go b/openrtb/native/response/eventtracker_easyjson.go index f5eb6b2..8fb0c18 100644 --- a/openrtb/native/response/eventtracker_easyjson.go +++ b/openrtb/native/response/eventtracker_easyjson.go @@ -48,12 +48,8 @@ func easyjson88abeb4cDecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. in.AddError((out.CustomData).UnmarshalJSON(data)) } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -89,16 +85,10 @@ func easyjson88abeb4cEncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite out.RawString(prefix) out.Raw((in.CustomData).MarshalJSON()) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/image.go b/openrtb/native/response/image.go index 08cadd1..3e58134 100644 --- a/openrtb/native/response/image.go +++ b/openrtb/native/response/image.go @@ -1,6 +1,10 @@ package response -import "github.com/Vungle/vungo/openrtb/native" +import ( + "encoding/json" + + "github.com/Vungle/vungo/openrtb/native" +) // Image object to be used for all image elements of the Native ad such as Icons, Main Image, etc. // It is recommended that if assetsurl/dcourl is being used rather than embedded assets, that an image of each @@ -64,5 +68,5 @@ type Image struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/image_easyjson.go b/openrtb/native/response/image_easyjson.go index 8f175e9..4bde872 100644 --- a/openrtb/native/response/image_easyjson.go +++ b/openrtb/native/response/image_easyjson.go @@ -46,12 +46,8 @@ func easyjson220accf5DecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. case "h": out.H = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -93,16 +89,10 @@ func easyjson220accf5EncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite out.RawString(prefix) out.Int64(int64(in.H)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/link.go b/openrtb/native/response/link.go index 6a31590..dc043db 100644 --- a/openrtb/native/response/link.go +++ b/openrtb/native/response/link.go @@ -1,5 +1,7 @@ package response +import "encoding/json" + // Link object is used for ‘call to action’ assets, or other links from the Native ad. // This Object should be associated to its peer object in the parent Asset Object or as the master link in the top level // Native Ad response object. When that peer object is activated (clicked) the action should take the user to the @@ -49,5 +51,5 @@ type Link struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/link_easyjson.go b/openrtb/native/response/link_easyjson.go index a2659f3..e1c015c 100644 --- a/openrtb/native/response/link_easyjson.go +++ b/openrtb/native/response/link_easyjson.go @@ -64,12 +64,8 @@ func easyjson16eb09bcDecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. case "fallback": out.Fallback = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -109,16 +105,10 @@ func easyjson16eb09bcEncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite out.RawString(prefix) out.String(string(in.Fallback)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/response.go b/openrtb/native/response/response.go index 81f4e17..2b37db9 100644 --- a/openrtb/native/response/response.go +++ b/openrtb/native/response/response.go @@ -1,5 +1,7 @@ package response +import "encoding/json" + // Response object is the top level JSON object which identifies a native response. // // See OpenRTB Native 1.2 Sec 5.1 Native Markup Response Object @@ -124,5 +126,5 @@ type Response struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/response_easyjson.go b/openrtb/native/response/response_easyjson.go index 3abb6e6..7a54cd9 100644 --- a/openrtb/native/response/response_easyjson.go +++ b/openrtb/native/response/response_easyjson.go @@ -118,12 +118,8 @@ func easyjson6ff3ac1dDecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. case "privacy": out.Privacy = string(in.String()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -232,16 +228,10 @@ func easyjson6ff3ac1dEncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite out.RawString(prefix) out.String(string(in.Privacy)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native/response/title.go b/openrtb/native/response/title.go index 1a1b26d..cb64c33 100644 --- a/openrtb/native/response/title.go +++ b/openrtb/native/response/title.go @@ -1,5 +1,7 @@ package response +import "encoding/json" + // Title corresponds to the Title Object in the request, with the value filled in. // If using assetsurl or dcourl response rather than embedded asset response, it is recommended that three title objects // be provided, the length of each of which is less than or equal to the three recommended maximum title lengths @@ -39,5 +41,5 @@ type Title struct { // Description: // This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility // beyond the standard defined in this specification. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } diff --git a/openrtb/native/response/title_easyjson.go b/openrtb/native/response/title_easyjson.go index bac7b9b..473a536 100644 --- a/openrtb/native/response/title_easyjson.go +++ b/openrtb/native/response/title_easyjson.go @@ -41,12 +41,8 @@ func easyjsonE7952480DecodeGithubComVungleVungoOpenrtbNativeResponse(in *jlexer. case "len": out.Len = int64(in.Int64()) case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -72,16 +68,10 @@ func easyjsonE7952480EncodeGithubComVungleVungoOpenrtbNativeResponse(out *jwrite out.RawString(prefix) out.Int64(int64(in.Len)) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/native_easyjson.go b/openrtb/native_easyjson.go index 25f78f7..cba003f 100644 --- a/openrtb/native_easyjson.go +++ b/openrtb/native_easyjson.go @@ -87,12 +87,8 @@ func easyjson3eeb1cddDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Na in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -146,16 +142,10 @@ func easyjson3eeb1cddEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in N out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/openrtbtest/testutil.go b/openrtb/openrtbtest/testutil.go index d53be4d..eed15d9 100644 --- a/openrtb/openrtbtest/testutil.go +++ b/openrtb/openrtbtest/testutil.go @@ -13,6 +13,7 @@ import ( "github.com/Vungle/vungo/internal/util/utiltest" "github.com/Vungle/vungo/openrtb" "github.com/go-test/deep" + "github.com/google/go-cmp/cmp" ) // UnmarshalFromJSONFile method reads from a testdata/*.json file and unmarshals the content into @@ -60,11 +61,8 @@ func VerifyModelAgainstFile(t Testing, file string, modelType reflect.Type) { t.Fatalf("Cannot unmarshal JSON data into %v because of\n%v.", modelType, err) } - if !reflect.DeepEqual(model1, model2) { - m1JSON, _ := json.MarshalIndent(model1, "", " ") - m2JSON, _ := json.MarshalIndent(model2, "", " ") - t.Logf("Unmarshaled: %s\nRe-marshaled: %s.", m1JSON, m2JSON) - t.Error("Unmarshaled model should be the same as re-marshaled model.") + if d := cmp.Diff(model1, model2); d != "" { + t.Errorf("Reduce() mismatch (-got +want):\n%s", d) } verifyModelNonEmptyFields(t, jsonBytes, modelType) @@ -79,7 +77,7 @@ func verifyModelNonEmptyFields(t Testing, jsonBytes []byte, modelType reflect.Ty // TODO(@garukun): Consider encapsulate pretty-printing JSON into a common library call for // testing. buf := bytes.NewBuffer(make([]byte, 0, len(jsonBytes))) - json.Indent(buf, jsonBytes, "", " ") + _ = json.Indent(buf, jsonBytes, "", " ") t.Log(buf.String()) t.Fatalf("Cannot unmarshal json onto %v.\n%v", modelType, err) @@ -197,7 +195,7 @@ func NewBidRequestForTesting(id string, impressionID string) *openrtb.BidRequest return &openrtb.BidRequest{ ID: id, Impressions: []*openrtb.Impression{ - &openrtb.Impression{ + { ID: impressionID, BidFloorCurrency: openrtb.CurrencyUSD, }, @@ -304,7 +302,7 @@ func verifyDeepCopyImpl(prefix string, src, dst reflect.Value) []string { } if src.CanAddr() && dst.CanAddr() && dst.Addr() == src.Addr() { r = append(r, fmt.Sprintf("%v share\n\tgot %#+v\n\twant %#+v\n", - prefix, dst.Addr(), src.Addr())) + prefix, dst.Kind().String(), src.Kind().String())) } switch src.Kind() { case reflect.Ptr: diff --git a/openrtb/openrtbutil/request_test.go b/openrtb/openrtbutil/request_test.go index 20150f8..faafd72 100644 --- a/openrtb/openrtbutil/request_test.go +++ b/openrtb/openrtbutil/request_test.go @@ -2,7 +2,6 @@ package openrtbutil_test import ( "context" - "encoding/json" "net/url" "reflect" "testing" @@ -31,21 +30,6 @@ func TestNewRequestError(t *testing.T) { openrtbutil.ErrEmptyURL.Error(), }, - // Should return JSON marshaling error. - { - &openrtb.BidRequest{ - Application: &openrtb.Application{ - // Fake a JSON marshaling error by creating an impossible-to-marshal value. - Extension: func() {}, - }, - }, - "http://localhost", - []reflect.Type{ - reflect.TypeOf((*json.MarshalerError)(nil)), - reflect.TypeOf((*json.UnsupportedTypeError)(nil)), - }, // seems like diff os will report diff err type - }, - // Should return URL parsing error. { &openrtb.BidRequest{}, diff --git a/openrtb/privatemarketplace.go b/openrtb/privatemarketplace.go index ae7cfe4..6a9b2a1 100644 --- a/openrtb/privatemarketplace.go +++ b/openrtb/privatemarketplace.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // PrivateMarketplace type contains additional metadata about an impression such that individual // buyers are encouraged to buy the impressions via a different channel. @@ -8,9 +12,9 @@ import "github.com/Vungle/vungo/internal/util" //go:generate easyjson $GOFILE //easyjson:json type PrivateMarketplace struct { - IsPrivateAuction NumericBool `json:"private_auction"` - Deals []*Deal `json:"deals"` - Extension interface{} `json:"ext,omitempty"` + IsPrivateAuction NumericBool `json:"private_auction"` + Deals []*Deal `json:"deals"` + Extension json.RawMessage `json:"ext,omitempty"` } // Copy returns a pointer to a copy of the Impression object. @@ -27,6 +31,6 @@ func (pmp *PrivateMarketplace) Copy() *PrivateMarketplace { } } - pmpCopy.Extension = util.DeepCopyCopiable(pmp.Extension) + pmpCopy.Extension = util.DeepCopyJSONRawMsg(pmp.Extension) return &pmpCopy } diff --git a/openrtb/privatemarketplace_easyjson.go b/openrtb/privatemarketplace_easyjson.go index f5d301f..b192423 100644 --- a/openrtb/privatemarketplace_easyjson.go +++ b/openrtb/privatemarketplace_easyjson.go @@ -72,12 +72,8 @@ func easyjsonE1675e4eDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Pr in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -118,16 +114,10 @@ func easyjsonE1675e4eEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in P out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/producer.go b/openrtb/producer.go index d5531d4..151472b 100644 --- a/openrtb/producer.go +++ b/openrtb/producer.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Producer object defines the producer of the content in which the ad will be // shown. @@ -53,7 +57,7 @@ type Producer struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Site object contains required and @@ -71,6 +75,6 @@ func (p *Producer) Copy() *Producer { } pCopy := *p pCopy.Cat = util.DeepCopyStrSlice(p.Cat) - pCopy.Ext = util.DeepCopyCopiable(p.Ext) + pCopy.Ext = util.DeepCopyJSONRawMsg(p.Ext) return &pCopy } diff --git a/openrtb/producer_easyjson.go b/openrtb/producer_easyjson.go index f77230b..c9f0d7c 100644 --- a/openrtb/producer_easyjson.go +++ b/openrtb/producer_easyjson.go @@ -66,12 +66,8 @@ func easyjson92a4b12aDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Pr case "domain": out.Domain = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -132,7 +128,7 @@ func easyjson92a4b12aEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in P } out.String(string(in.Domain)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -140,13 +136,7 @@ func easyjson92a4b12aEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in P } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/regulation.go b/openrtb/regulation.go index 3cbe342..c9c062f 100644 --- a/openrtb/regulation.go +++ b/openrtb/regulation.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Regulation types denotes any industry, legal, or governmental regulations with respect to the // parent bid request object. @@ -8,8 +12,8 @@ import "github.com/Vungle/vungo/internal/util" //go:generate easyjson $GOFILE //easyjson:json type Regulation struct { - IsCoppaCompliant *NumericBool `json:"coppa,omitempty"` - Extension interface{} `json:"ext,omitempty"` + IsCoppaCompliant *NumericBool `json:"coppa,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Copy returns a pointer to a copy of the Regulation object. @@ -22,7 +26,7 @@ func (r *Regulation) Copy() *Regulation { coppaCopy := *r.IsCoppaCompliant regulationCopy.IsCoppaCompliant = &coppaCopy } - regulationCopy.Extension = util.DeepCopyCopiable(r.Extension) + regulationCopy.Extension = util.DeepCopyJSONRawMsg(r.Extension) return ®ulationCopy } diff --git a/openrtb/regulation_easyjson.go b/openrtb/regulation_easyjson.go index e3a31b1..3a50ce9 100644 --- a/openrtb/regulation_easyjson.go +++ b/openrtb/regulation_easyjson.go @@ -49,12 +49,8 @@ func easyjson1db63384DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Re } } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -76,7 +72,7 @@ func easyjson1db63384EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in R out.RawString(prefix[1:]) out.Raw((*in.IsCoppaCompliant).MarshalJSON()) } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -84,13 +80,7 @@ func easyjson1db63384EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in R } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/segment.go b/openrtb/segment.go index c14d138..48f2f58 100644 --- a/openrtb/segment.go +++ b/openrtb/segment.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Segment objects are essentially key-value pairs that convey specific units of // data. @@ -43,7 +47,7 @@ type Segment struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Site object contains required and @@ -60,6 +64,6 @@ func (s *Segment) Copy() *Segment { return nil } sCopy := *s - sCopy.Ext = util.DeepCopyCopiable(s.Ext) + sCopy.Ext = util.DeepCopyJSONRawMsg(s.Ext) return &sCopy } diff --git a/openrtb/segment_easyjson.go b/openrtb/segment_easyjson.go index 7fb159d..6a1514e 100644 --- a/openrtb/segment_easyjson.go +++ b/openrtb/segment_easyjson.go @@ -43,12 +43,8 @@ func easyjson88ee421DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Seg case "value": out.Value = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -90,7 +86,7 @@ func easyjson88ee421EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in Se } out.String(string(in.Value)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -98,13 +94,7 @@ func easyjson88ee421EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in Se } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/site.go b/openrtb/site.go index 10d00b4..70ca25f 100644 --- a/openrtb/site.go +++ b/openrtb/site.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Site object should be included if the ad supported content is a website as // opposed to a non-browser application. @@ -133,7 +137,7 @@ type Site struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Validate method checks to see if the Site object contains required and @@ -157,6 +161,6 @@ func (s *Site) Copy() *Site { sCopy.PrivacyPolicy = s.PrivacyPolicy.Copy() sCopy.Publisher = s.Publisher.Copy() sCopy.Content = s.Content.Copy() - sCopy.Ext = util.DeepCopyCopiable(s.Ext) + sCopy.Ext = util.DeepCopyJSONRawMsg(s.Ext) return &sCopy } diff --git a/openrtb/site_easyjson.go b/openrtb/site_easyjson.go index d4718c4..fb6f68c 100644 --- a/openrtb/site_easyjson.go +++ b/openrtb/site_easyjson.go @@ -164,12 +164,8 @@ func easyjsonD9064c5DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Sit case "keywords": out.Keywords = string(in.String()) case "ext": - if m, ok := out.Ext.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Ext.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Ext = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Ext).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -348,7 +344,7 @@ func easyjsonD9064c5EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in Si } out.String(string(in.Keywords)) } - if in.Ext != nil { + if len(in.Ext) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -356,13 +352,7 @@ func easyjsonD9064c5EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in Si } else { out.RawString(prefix) } - if m, ok := in.Ext.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Ext.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Ext)) - } + out.Raw((in.Ext).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/source.go b/openrtb/source.go index 0cc9429..ed68fd3 100644 --- a/openrtb/source.go +++ b/openrtb/source.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // Source object describes the nature and behavior of the entity that is the source of the bid request upstream from the exchange. // The primary purpose of this object is to define post-auction or upstream decisioning when the exchange itself does not control the final decision. @@ -40,7 +44,7 @@ type Source struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Ext interface{} `json:"ext,omitempty"` + Ext json.RawMessage `json:"ext,omitempty"` } // Copy returns a pointer to a copy of the Source object. @@ -49,6 +53,6 @@ func (s *Source) Copy() *Source { return nil } sourceCopy := *s - sourceCopy.Ext = util.DeepCopyCopiable(s.Ext) + sourceCopy.Ext = util.DeepCopyJSONRawMsg(s.Ext) return &sourceCopy } diff --git a/openrtb/testdata/bidrequest.json b/openrtb/testdata/bidrequest.json index 06083dd..a170629 100644 --- a/openrtb/testdata/bidrequest.json +++ b/openrtb/testdata/bidrequest.json @@ -130,26 +130,7 @@ "coppa": 1 }, "source": { - "ext": { - "schain": { - "ver": "1.0", - "complete": 1, - "nodes": [ - { - "asi": "directseller.com", - "sid": "00001", - "rid": "BidRequest1", - "hp": 1 - }, - { - "asi": "reseller.com", - "sid": "aaaaa", - "rid": "BidRequest2", - "hp": 1 - } - ] - } - } + "ext": {"schain":{"ver":"1.0","complete":1,"nodes":[{"asi":"directseller.com","sid":"00001","rid":"BidRequest1","hp":1},{"asi":"reseller.com","sid":"aaaaa","rid":"BidRequest2","hp":1}]}} }, "ext": {} } diff --git a/openrtb/testdata/regulation.json b/openrtb/testdata/regulation.json index bd5bbca..bfa8414 100644 --- a/openrtb/testdata/regulation.json +++ b/openrtb/testdata/regulation.json @@ -1,6 +1 @@ -{ - "coppa": 1, - "ext": { - "gdpr": 1 - } -} +{"coppa":1,"ext":{"gdpr":1}} diff --git a/openrtb/user.go b/openrtb/user.go index d8e5aa8..56cfbdf 100644 --- a/openrtb/user.go +++ b/openrtb/user.go @@ -1,6 +1,10 @@ package openrtb -import "github.com/Vungle/vungo/internal/util" +import ( + "encoding/json" + + "github.com/Vungle/vungo/internal/util" +) // User type contains known or derived information about the human user of the device; i.e., the // audience of the audience for advertising. @@ -9,15 +13,15 @@ import "github.com/Vungle/vungo/internal/util" //go:generate easyjson $GOFILE //easyjson:json type User struct { - ID string `json:"id,omitempty"` - BuyerID string `json:"buyeruid,omitempty"` - BirthYear int `json:"yob,omitempty"` - Gender Gender `json:"gender,omitempty"` - Keywords string `json:"keywords,omitempty"` - CustomData string `json:"customdata,omitempty"` - Geo *Geo `json:"geo,omitempty"` - Data []Data `json:"data,omitempty"` - Extension interface{} `json:"ext,omitempty"` + ID string `json:"id,omitempty"` + BuyerID string `json:"buyeruid,omitempty"` + BirthYear int `json:"yob,omitempty"` + Gender Gender `json:"gender,omitempty"` + Keywords string `json:"keywords,omitempty"` + CustomData string `json:"customdata,omitempty"` + Geo *Geo `json:"geo,omitempty"` + Data []Data `json:"data,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Copy returns a pointer to a copy of the User object. @@ -28,7 +32,7 @@ func (u *User) Copy() *User { userCopy := *u if u.Geo != nil { - GeoCopy := *u.Geo + GeoCopy := *u.Geo.Copy() userCopy.Geo = &GeoCopy } @@ -37,7 +41,7 @@ func (u *User) Copy() *User { copy(userCopy.Data, u.Data) } - userCopy.Extension = util.DeepCopyCopiable(u.Extension) + userCopy.Extension = util.DeepCopyJSONRawMsg(u.Extension) return &userCopy } diff --git a/openrtb/user_easyjson.go b/openrtb/user_easyjson.go index 6be1538..5bf8ce7 100644 --- a/openrtb/user_easyjson.go +++ b/openrtb/user_easyjson.go @@ -82,12 +82,8 @@ func easyjson9e1087fdDecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Us in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -188,7 +184,7 @@ func easyjson9e1087fdEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in U out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" if first { first = false @@ -196,13 +192,7 @@ func easyjson9e1087fdEncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in U } else { out.RawString(prefix) } - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') } diff --git a/openrtb/video.go b/openrtb/video.go index cb01be8..18ba488 100644 --- a/openrtb/video.go +++ b/openrtb/video.go @@ -1,6 +1,7 @@ package openrtb import ( + "encoding/json" "errors" "github.com/Vungle/vungo/internal/util" @@ -260,7 +261,7 @@ type Video struct { // object // Description: // Placeholder for exchange-specific extensions to OpenRTB. - Extension interface{} `json:"ext,omitempty"` + Extension json.RawMessage `json:"ext,omitempty"` } // Validate method implements a Validater interface and return a validation error according to the @@ -325,7 +326,7 @@ func (v *Video) Copy() *Video { copy(vCopy.CompanionTypes, v.CompanionTypes) } - vCopy.Extension = util.DeepCopyCopiable(v.Extension) + vCopy.Extension = util.DeepCopyJSONRawMsg(v.Extension) return &vCopy } diff --git a/openrtb/video_easyjson.go b/openrtb/video_easyjson.go index f52e3fc..9194cd1 100644 --- a/openrtb/video_easyjson.go +++ b/openrtb/video_easyjson.go @@ -283,12 +283,8 @@ func easyjson3c9ce8c3DecodeGithubComVungleVungoOpenrtb(in *jlexer.Lexer, out *Vi in.Delim(']') } case "ext": - if m, ok := out.Extension.(easyjson.Unmarshaler); ok { - m.UnmarshalEasyJSON(in) - } else if m, ok := out.Extension.(json.Unmarshaler); ok { - _ = m.UnmarshalJSON(in.Raw()) - } else { - out.Extension = in.Interface() + if data := in.Raw(); in.Ok() { + in.AddError((out.Extension).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -508,16 +504,10 @@ func easyjson3c9ce8c3EncodeGithubComVungleVungoOpenrtb(out *jwriter.Writer, in V out.RawByte(']') } } - if in.Extension != nil { + if len(in.Extension) != 0 { const prefix string = ",\"ext\":" out.RawString(prefix) - if m, ok := in.Extension.(easyjson.Marshaler); ok { - m.MarshalEasyJSON(out) - } else if m, ok := in.Extension.(json.Marshaler); ok { - out.Raw(m.MarshalJSON()) - } else { - out.Raw(json.Marshal(in.Extension)) - } + out.Raw((in.Extension).MarshalJSON()) } out.RawByte('}') }