You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
slzhffktm
changed the title
Breaking Change on v4.12.0 When Binding to map[string]interface{}
Breaking Change on v4.12.0 When Binding to map[string]interface{} -> the field become list
Jun 27, 2024
@slzhffktm I've submitted a pull request (#2656) that addresses this issue by maintaining backwards compatibility for map[string]interface{} binding while supporting the new functionality.
The PR modifies the bindData function to:
Store single values as strings
Store multiple values as []string
However, if the maintainers decide not to merge this change, here's an alternative solution you can use in your code to achieve the same result:
You can use this helper function with new version without breaking code regardless of whether the PR is merged. It processes the map[string]interface{} returned by c.Bind() and converts any []string values to single strings if they contain only one element.
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
The code
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
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
Version/commit
v4.12.0
The text was updated successfully, but these errors were encountered: