Moved from python to golang:
jsonBlob := `{ "test" : {"thing":["team1", "team2"]}}`
type other map[string]Myset
type stuff map[string]other
type MySet struct {
set mapset.Set
}
//Custom unmarshaller
func (s *MySet) UnmarshalJSON(p []byte) error {
var a []interface{}
if err := json.Unmarshal(p, &a); err != nil {
return err
}
s.set = mapset.NewSet(a)
return nil
}
// Unmarshall it
var s stuff
err := json.Unmarshall(jsonBlob, &s)
if err != nil {
return err
}
but it throws: runtime error: hash of unhashable type []interface {}
Given that the data type you wish to use is an interface, and does not satisfy the json.Unmarshaler interface, you have two options:
Unmarshal to an array, then convert to your preferred type.
Create a custom type, that wraps your preferred type, and provides an UnmarshalJSON
method. This is functionally the same as #1, but may be easier to use. Example:
type MySet struct {
set mapset.Set
}
func (s *MySet) UnmarshalJSON(p []byte) error {
var a []interface{}
if err := json.Unmarshal(p, &a); err != nil {
return err
}
s.set = mapset.NewSet(a)
return nil
}
(Note, this code is untested; it is not meant to be a complete solution, but a guide in the right direction.)