File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package openrtb
22
33import (
44 "encoding/json"
5+ "errors"
56 "strconv"
67)
78
@@ -51,3 +52,27 @@ func (n *StringOrNumber) UnmarshalJSON(data []byte) error {
5152 }
5253 return nil
5354}
55+
56+ // BoolOrNumber attemps to fix OpenRTB incompatibilities where a field is expected as bool but the spec expects int values. This was not seen till now, but some mediation partners will follow the spec closely.
57+ type BoolOrNumber bool
58+
59+ // UnmarshalJSON implements json.Unmarshaler
60+ func (b * BoolOrNumber ) UnmarshalJSON (data []byte ) error {
61+ var val interface {}
62+ if err := json .Unmarshal (data , & val ); err != nil {
63+ return err
64+ }
65+
66+ switch v := val .(type ) {
67+ case bool :
68+ * b = BoolOrNumber (v )
69+ case float64 :
70+ // When unmarshaling JSON into an interface value, Unmarshal stores JSON numbers in the interface value float64
71+ * b = BoolOrNumber (v != 0 )
72+ default :
73+
74+ return errors .New ("BoolOrInt: invalid type" )
75+ }
76+
77+ return nil
78+ }
Original file line number Diff line number Diff line change @@ -841,10 +841,10 @@ type ChannelEntity struct {
841841
842842// RegExtension Extension object for Regulations
843843type RegExtension struct {
844- GDPR int `json:"gdpr,omitempty"`
845- LGPD bool `json:"lgpd,omitempty"`
846- PIPL bool `json:"pipl,omitempty"`
847- USPrivacy string `json:"us_privacy,omitempty"`
844+ GDPR int `json:"gdpr,omitempty"`
845+ LGPD BoolOrNumber `json:"lgpd,omitempty"`
846+ PIPL BoolOrNumber `json:"pipl,omitempty"`
847+ USPrivacy string `json:"us_privacy,omitempty"`
848848}
849849
850850// UserExtension Extension object for User
You can’t perform that action at this time.
0 commit comments