-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Clone() does a deep clone of inner map[string]interface{} and mapstr.M values. But if a map is contained in an array then the value is not cloned. For example, if an object like this were Clone()ed then map within array would not be cloned because Clone() does not look inside []interface{}.
mapstr.M{
"array": []interface{}{
map[string]interface{}{
"key": "value",
},
},
} One use case is Filebeat's httpjson input. It uses heavily uses Clone() and as a result arrays object's do not behave as expected. It depends on the result of Clone() only containing mapstr.M (and not map[string]interface{}). It needs mapstr.M's implementation of fmt.Stringer that returns json.
As a possible workaround, httpjson has been considering its own deepClone(mapstr.M) mapstr.M (workaround.go.txt) implementation. But I think it would be better if mapstr.M Clone's implementation automatically handled arrays.
Relates: elastic/beats#32472