diff --git a/objects.go b/objects.go index c0b1dc48..39436efe 100644 --- a/objects.go +++ b/objects.go @@ -3,6 +3,7 @@ package ibclient import ( "bytes" "encoding/json" + "fmt" "reflect" ) @@ -546,14 +547,26 @@ func (ea *EA) UnmarshalJSON(b []byte) (err error) { *ea = make(EA) for k, v := range m { val := v["value"] - if reflect.TypeOf(val).String() == "json.Number" { + switch valType := reflect.TypeOf(val).String(); valType { + case "json.Number": var i64 int64 i64, err = val.(json.Number).Int64() val = int(i64) - } else if val.(string) == "True" { - val = Bool(true) - } else if val.(string) == "False" { - val = Bool(false) + case "string": + if val.(string) == "True" { + val = Bool(true) + } else if val.(string) == "False" { + val = Bool(false) + } + case "[]interface {}": + nval := val.([]interface{}) + nVals := make([]string, len(nval)) + for i, v := range nval { + nVals[i] = fmt.Sprintf("%v", v) + } + val = nVals + default: + val = fmt.Sprintf("%v", val) } (*ea)[k] = val diff --git a/objects_test.go b/objects_test.go index 14bf071c..009f01b6 100644 --- a/objects_test.go +++ b/objects_test.go @@ -77,11 +77,13 @@ var _ = Describe("Objects", func() { "Tenant Name": "Engineering01", "Maximum Wait Time": 120, "DNS Support": Bool(false), + "Routers": []string{"10.1.2.234", "10.1.2.235"}, } eaJSON := `{"Cloud API Owned":{"value":"True"},` + `"Tenant Name":{"value":"Engineering01"},` + `"Maximum Wait Time":{"value":120},` + - `"DNS Support":{"value":"False"}}` + `"DNS Support":{"value":"False"},` + + `"Routers":{"value":["10.1.2.234", "10.1.2.235"]}}` Context("Marshalling", func() { Context("expected JSON is returned", func() {