@@ -62,7 +62,7 @@ type User struct {
62
62
// True if the user's email is verified, false otherwise. If it is true then
63
63
// the user will not receive a verification email, unless verify_email: true
64
64
// was specified.
65
- EmailVerified * bool `json:"email_verified,omitempty "`
65
+ EmailVerified * bool `json:"- "`
66
66
67
67
// If true, the user will receive a verification email after creation, even
68
68
// if created with email_verified set to true. If false, the user will not
@@ -87,6 +87,58 @@ type User struct {
87
87
Blocked * bool `json:"blocked,omitempty"`
88
88
}
89
89
90
+ // UnmarshalJSON is a custom deserializer for the User type.
91
+ //
92
+ // We have to use a custom one due to possible inconsistencies in value types.
93
+ func (u * User ) UnmarshalJSON (b []byte ) error {
94
+ type user User
95
+ type userAlias struct {
96
+ * user
97
+ RawEmailVerified interface {} `json:"email_verified,omitempty"`
98
+ }
99
+
100
+ alias := & userAlias {(* user )(u ), nil }
101
+
102
+ err := json .Unmarshal (b , alias )
103
+ if err != nil {
104
+ return err
105
+ }
106
+
107
+ if alias .RawEmailVerified != nil {
108
+ var emailVerified bool
109
+ switch rawEmailVerified := alias .RawEmailVerified .(type ) {
110
+ case bool :
111
+ emailVerified = rawEmailVerified
112
+ case string :
113
+ emailVerified , err = strconv .ParseBool (rawEmailVerified )
114
+ if err != nil {
115
+ return err
116
+ }
117
+ default :
118
+ panic (reflect .TypeOf (rawEmailVerified ))
119
+ }
120
+ alias .EmailVerified = & emailVerified
121
+ }
122
+
123
+ return nil
124
+ }
125
+
126
+ // MarshalJSON is a custom serializer for the User type.
127
+ func (u * User ) MarshalJSON () ([]byte , error ) {
128
+ type user User
129
+ type userAlias struct {
130
+ * user
131
+ RawEmailVerified interface {} `json:"email_verified,omitempty"`
132
+ }
133
+
134
+ alias := & userAlias {user : (* user )(u )}
135
+ if u .EmailVerified != nil {
136
+ alias .RawEmailVerified = u .EmailVerified
137
+ }
138
+
139
+ return json .Marshal (alias )
140
+ }
141
+
90
142
type UserIdentity struct {
91
143
Connection * string `json:"connection,omitempty"`
92
144
UserID * string `json:"-"`
0 commit comments