Skip to content

Commit

Permalink
support more type to umnarshaJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhi.li committed Jan 18, 2024
1 parent 56d9949 commit dd6281f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/set/stringset.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ func (set StringSet) MarshalJSON() ([]byte, error) {
// If 'data' contains JSON string, the set contains the string as one element.
// If 'data' contains Other JSON types, JSON parse error is returned.
func (set *StringSet) UnmarshalJSON(data []byte) error {
sl := []string{}
sl := []interface{}{}
var err error
if err = json.Unmarshal(data, &sl); err == nil {
*set = make(StringSet)
for _, s := range sl {
set.Add(s)
set.Add(fmt.Sprintf("%v", s))
}
} else {
var s string
var s interface{}
if err = json.Unmarshal(data, &s); err == nil {
*set = make(StringSet)
set.Add(s)
set.Add(fmt.Sprintf("%v", s))
}
}

Expand Down

0 comments on commit dd6281f

Please sign in to comment.