Skip to content

Commit

Permalink
Add additional string to bool conversion for boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
riton committed Nov 12, 2021
1 parent 27526e2 commit f52fb71
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gen/freeipa.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,27 @@ func (out *{{.UpperName}}) UnmarshalJSON(data []byte) error {
itemV, itemOk := rawItem.({{ToGoType .Type}})
{{end}}
if !itemOk {
{{if eq "bool" (ToGoType .Type)}}
// See https://github.com/tehwalris/go-freeipa/issues/3
// Sometimes IPA returns ["TRUE"] as a boolean value
strV, strOk := rawItem.(string)
if strOk {
boolV, err := strconv.ParseBool(strV)
if err != nil {
sliceOk = false
break
}

itemV = boolV
} else {
sliceOk = false
break
}
{{else}}
sliceOk = false
break
{{end}}

}
{{if eq "int" (ToGoType .Type)}}
intV, e := strconv.Atoi(itemV)
Expand Down

0 comments on commit f52fb71

Please sign in to comment.