Checklist
Description
I have at least one user in my tenant where email verified is true as a string
{
"email_verified": "true",
}
When I use the SDK to load the user, it fails to unmarshal, returning the error json: cannot unmarshal string into Go struct field .embed.email_verified of type bool
Expectation
The SDK should successfully load the response without throwing an error and with parsing the string value as a boolean
The v1 version of the SDK had this code to support the issue.
// UnmarshalJSON is a custom deserializer for the User type.
//
// We have to use a custom one due to possible inconsistencies in value types.
func (u *User) UnmarshalJSON(b []byte) error {
type user User
type userAlias struct {
*user
RawEmailVerified interface{} `json:"email_verified,omitempty"`
}
alias := &userAlias{(*user)(u), nil}
err := json.Unmarshal(b, alias)
if err != nil {
return err
}
if alias.RawEmailVerified != nil {
var emailVerified bool
switch rawEmailVerified := alias.RawEmailVerified.(type) {
case bool:
emailVerified = rawEmailVerified
case string:
emailVerified, err = strconv.ParseBool(rawEmailVerified)
if err != nil {
return err
}
default:
panic(reflect.TypeOf(rawEmailVerified))
}
alias.EmailVerified = &emailVerified
}
return nil
}
Reproduction
- Have a user where the
email_verified value is a string
- Load the user through the SDK
- Observe error
json: cannot unmarshal string into Go struct field .embed.email_verified of type bool
Auth0 Go SDK version
2.9.0
Checklist
Description
I have at least one user in my tenant where email verified is
trueas a string{ "email_verified": "true", }When I use the SDK to load the user, it fails to unmarshal, returning the error
json: cannot unmarshal string into Go struct field .embed.email_verified of type boolExpectation
The SDK should successfully load the response without throwing an error and with parsing the string value as a boolean
The v1 version of the SDK had this code to support the issue.
Reproduction
email_verifiedvalue is a stringjson: cannot unmarshal string into Go struct field .embed.email_verified of type boolAuth0 Go SDK version
2.9.0