2016-01-15 09:23:12 -05:00
|
|
|
// +build json
|
|
|
|
|
2016-05-24 16:41:51 -04:00
|
|
|
package collect
|
2016-01-15 09:23:12 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-05-24 16:41:51 -04:00
|
|
|
func (this *StringList) UnmarshalJSON(data []byte) error {
|
2016-01-15 09:23:12 -05:00
|
|
|
var strarray []string
|
|
|
|
if err := json.Unmarshal(data, &strarray); err == nil {
|
2016-05-24 16:41:51 -04:00
|
|
|
*this = *NewStringList(strarray)
|
2016-01-15 09:23:12 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var rawstr string
|
|
|
|
if err := json.Unmarshal(data, &rawstr); err == nil {
|
|
|
|
strlist := strings.Split(rawstr, ",")
|
2016-05-24 16:41:51 -04:00
|
|
|
*this = *NewStringList(strlist)
|
2016-01-15 09:23:12 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("Unknown format of a string list: " + string(data))
|
|
|
|
}
|