Skip to content

Breaking Change on v4.12.0 When Binding to map[string]interface{} -> the field become list #2652

Closed
@slzhffktm

Description

@slzhffktm

Issue Description

Breaking change on v4.12.0:

The c.Bind is now mapping query params & request body to list of string.

Example:

POST /test?query=param

request body

{"field1": "somevalue"}

The code

request := make(map[string]interface{})
if err := c.Bind(&request); err != nil {
	return err
}

fmt.Printf("%#v", request)

Previous behaviour (pre v4.12.0):

Result: map[string]interface {}{"query":"param", "field1":"somevalue"}

Current behaviour (v4.12.0):

Result: map[string]interface {}{"query":[]string{"param"}, "field1":[]string{"somevalue"}}

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

The behaviour from the code above should keep on returning non-breaking change and still return this on the newest version:

Result: map[string]interface {}{"query":"param", "field1":"somevalue"}

Actual behaviour

In v4.12.0, the result from the code above returned different result:

Result: map[string]interface {}{"query":[]string{"param"}, "field1":[]string{"somevalue"}}

Steps to reproduce

Working code to debug

package main

func main() {
}

Version/commit

v4.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions