Reputation: 49371
Looking at the following golang code:
b := []byte(`["a", "b"]`)
var value interface{}
json.Unmarshal(b, &value)
fmt.Println(value) // Print [a b]
fmt.Println(reflect.TypeOf(value)) //Print []interface {}
var targetValue interface{} = []string{"a", "b"}
if reflect.DeepEqual(value.([]interface{}), targetValue) {
t.Error("please be equal")
}
Am I expecting too much of DeepEqual
? Reading the documentation, the following statements reinforce my assumption that it should work:
What am I missing here?
Upvotes: 1
Views: 1801
Reputation: 79576
You're comparing a []interface{}
against []string
, which should never be equal.
if reflect.DeepEqual(value.([]interface{}), targetValue) {
compared against targetValue
which is of type []string
:
var targetValue interface{} = []string{"a", "c"}
Upvotes: 5