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
2
2
3
3
import (
4
4
"encoding/json"
5
+ "errors"
5
6
"strconv"
6
7
)
7
8
@@ -51,3 +52,27 @@ func (n *StringOrNumber) UnmarshalJSON(data []byte) error {
51
52
}
52
53
return nil
53
54
}
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 {
841
841
842
842
// RegExtension Extension object for Regulations
843
843
type 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"`
848
848
}
849
849
850
850
// UserExtension Extension object for User
You can’t perform that action at this time.
0 commit comments