Description

When I use Bind to parse a parameter with an error, c.JSON responds to the data without a Content-Type. It is possible to work with ShouldBind...

If ShouldBind can completely replace Bind, then the Bind function should be marked as deprecated.

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
)

type SS struct {
    AA string `json:"aa" form:"aa"  binding:"required"`
}

func main() {
    r := gin.Default()
    r.Use(func(c *gin.Context) {
        c.Next()
    })

    r.GET("/ping2", func(c *gin.Context) {
        if err := c.BindQuery(&SS{}); err != nil {
            c.JSON(500, &SS{AA: "dddd"})
            return
        }
        c.JSON(200, &SS{AA: "dddd"})
    })
    r.Run()
}

## Expectations

<!-- Your expectation result of 'curl' command, like -->

$ curl http://localhost:9000/hello/world Hello world


## Actual result

<!-- Actual result showing the problem -->

curl -I -X GET 127.0.0.1:8080/ping2
HTTP/1.1 500 Internal Server Error Content-Type: application/json; charset=utf-8 Date: Fri, 10 Nov 2023 06:53:43 GMT Content-Length: 13

```

Environment

  • go version:1.20.0
  • gin version (or commit ref):v1.9.1
  • operating system: macos