Skip to content

mapstr.M.Clone() should clone []interface{} values #75

@andrewkroh

Description

@andrewkroh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions